Codeforces 152C Pocket Book

Source: Internet
Author: User

Time limit:2000MS Memory Limit:262144KB 64bit IO Format:%i64d &%i6 4u SubmitStatusPracticecodeforces 152C

Description

One day little Vasya found Mom's pocket book. The book Had  n  names of hers friends and unusually enough, each name is exactly& nbsp m letters long. Let's number the names From 1 to  n  in The order in which they is written.

As mom wasn ' t home, Vasya decided to play with Names:he chose three Integers  i , &N Bsp J ,   K   (1≤ I < j n ,  1≤ k m ), then he took names NUMBER&NB Sp i  and  J  and swapped their prefixes of Length  K . For example, if we take names "cbdad" and "AABRD" and Swap their prefixes with the length Of 3, the result would be names "aabad" and "CBDRD".

Wonder how many different names Vasya can write instead of name number 1, if Vasya was allowed to perform any Numbe R of the described actions. As Vasya performs each action, he chooses numbers i, J, K independently from the PR Evious moves and his choice are based entirely on his would. The sought number can be very large and so you should only find it modulo 1000000007(9 + 7).

Input

The first input line contains integers n and m (1≤ n, m ≤100)-the Number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.

Output

Print the single number-the number of different names this could end up in position number 1 in the Pocket book aft Er the applying the procedures described above. Print the number modulo 1000000007(9 + 7).

Sample Input

Input
2 3
AAB
BAA
Output
4
Input
4 5
Ababa
Bcgdg
AAAAA
Yabsa
Output
216

Hint

In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".

1#include <stdio.h>2#include <string.h>3#include <algorithm>4 using namespacestd;5 intMain ()6 {7     intn,m;8     inti,j,k;9     Chara[ the][ the];Ten     intb[ -]; One     Long Longc[1005]; A      while(SCANF ("%d%d", &n,&m)! =EOF) -     { -Memset (c,0,sizeof(c)); the          for(i=1; i<=n;i++) -scanf"%s", A[i]); -          for(i=0; i<m;i++) -         { +memset (b,0,sizeof(b)); -              for(j=1; j<=n;j++) +             { Ab[a[j][i]-'A']++; at             } -              for(j=0; j<= -; j + +) -                 if(B[j]) -c[i]++; -             //printf ("%i64d\n", C[i]); -         } in         Long Longans=c[0]; -          for(i=1; i<m;i++) toAns=ans* (c[i]%1000000007)%1000000007; +printf"%i64d\n", ans); -     } the     return 0; *}
View Code

Codeforces 152C Pocket Book

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.