code forces 152C Pocket Book

来源:互联网 发布:借贷管理系统源码 编辑:程序博客网 时间:2024/05/21 04:44

One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.

As mom wasn't home, Vasya decided to play with names: he chose three integers ijk (1 ≤ i < j ≤ n1 ≤ k ≤ m), then he took names number 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 will be names "AABAD" and "CBDRD".

You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers ijk independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).

Input

The first input line contains two 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 that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).

Example
Input
2 3AABBAA
Output
4
Input
4 5ABABABCGDGAAAAAYABSA
Output
216
Note

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


【题解】

 就简单的组合问题。每一列元素的种类数之积即为答案。


【AC代码】

#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>using namespace std;typedef long long ll;const int inf = 1e9+7;const int N=110;ll vis[N];char str[N][N];int main(){    ll ans,x,y;    while(~scanf("%lld%lld",&x,&y))    {        getchar();        ans=1;        for(int i=0;i<x;++i)            gets(str[i]);        for(int i=0;i<y;++i)        {            ll num=0;            memset(vis,0,sizeof vis);            for(int j=0;j<x;++j)            {                if(vis[str[j][i]-'0']==0)                {                    vis[str[j][i]-'0']=1;                    num++;                }            }            ans = ans*num%inf;        }        printf("%lld\n",ans);    }    return 0;}




原创粉丝点击