F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Word Game

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 149    Accepted Submission(s): 15


Problem Description
If you have a circle consists of L characters. We can define one of them as 0th character, and then 1st, 2nd ¡­¡­ (L -1)th along the clockwise. A string beginning with the ith character can be get from this circle, let's call it p[i] (All of these string has a length of L). From 0 to L -1, if there exists exactly K positions i make p[i] as same as p[0], then we call it a magic word.
Give you n strings and a K. Please use all of these strings to creat a new string p. Tell me how many ways exists to construct a string p and make it a magic word.
 

Input
The input contains several cases. Each case starts with two integer n and K. Then follows n lines, each line contain a string. 0 < n <= 8, 0 < K <= 200, each string contain between 1 and 20 characters. Input ends with a case n = 0 and K = 0.
 

Output
Each case print a line with an integer.
 

Sample Input
3 3 AAB AAB AAB 0 0
 

Sample Output
6
 

Hint
hints:
Use these strings, you can construct six "AABAABAAB".
 

Author
CTW
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-18 13:39:13, Gzip enabled