9
12
2015
1

C. Lucky Subsequence

C. Lucky Subsequence
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 477444 are lucky and 517467 are not.

Petya has sequence a consisting of n integers.

The subsequence of the sequence a is such subsequence that can be obtained from a by removing zero or more of its elements.

Two sequences are considered different if index sets of numbers included in them are different. That is, the values ​of the elements ​do not matter in the comparison of subsequences. In particular, any sequence of length n has exactly 2n different subsequences (including an empty subsequence).

A subsequence is considered lucky if it has a length exactly k and does not contain two identical lucky numbers (unlucky numbers can be repeated any number of times).

Help Petya find the number of different lucky subsequences of the sequence a. As Petya's parents don't let him play with large numbers, you should print the result modulo prime number 1000000007 (109 + 7).

Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105). The next line contains n integers ai (1 ≤ ai ≤ 109) — the sequence a.

Output

On the single line print the single number — the answer to the problem modulo prime number 1000000007 (109 + 7).

Sample test(s)
input
3 2
10 10 10
output
3
input
4 2
4 4 7 7
output
4
Note

In the first sample all 3 subsequences of the needed length are considered lucky.

In the second sample there are 4 lucky subsequences. For them the sets of indexes equal (the indexation starts from 1): {1, 3}{1, 4},{2, 3} and {2, 4}.

    星期六模拟赛的一道题。。。

    说是NOIP模拟赛我怎么觉得有点不像呢。。。果真我还是太弱了。。有种NOIP要爆蛋的即视感。。.

    比赛的时候很快就想到了把\(luckynum\)提出来然后再处理。。。然而我一直接一直在想先求出所有的排列。。然后减去不符合的。。然后就跑偏了。。。

    过了一个小时才发现直接求可能的方案简单多了。。。我们先只考虑\(luckynum\)。用\(dp\)处理,\(f[i][j]\)表示前\(i\)种数中取\(j\)种树的方案数。。。然后转移\(f[i][j] = f[i-1][j-1]*num[i]\)。。。然后无关的数求一下组合数统计答案就好了

 

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int mod = 1e9+7;
const int N = 100010;
int a[N],b[N],c[N],jc[N],jcn[N],f[N],num[N],tot,sum,ans,n,m,k;
int read(){
	int x = 0,f = 1,c = getchar();
	while (c<'0' || c>'9') {if (c=='-') f = -1;c = getchar();}
	while (c>='0' && c<='9') x = x*10+c-'0',c = getchar();
	return x*f;
}
int lucky(int x){
	if (x==0) return 0;
	while (x){
		int s = x%10;
		if (s!=4 && s!=7) return 0;
		x/=10;
	}
	return 1;
}
int ksm(int a,int k){
	int res = 1;
	for (;k;k>>=1,a=1ll*a*a%mod) if (k&1) res = 1ll*res*a%mod;
	return res;
}
int C(int n,int m){
	if (m>n) return 0;
	return 1ll*jc[n]*jcn[m]%mod*jcn[n-m]%mod;
}
int main(){
//	freopen("sequence.in","r",stdin);
//	freopen("sequence.out","w",stdout);
	n = read();k = read();
	jc[0] = jc[1] = 1;jcn[0] = jcn[1] = 1;
	for (int i=2;i<=n;i++) jc[i]=1ll*jc[i-1]*i%mod;
	jcn[n]=ksm(jc[n],mod-2);
	for (int i=n-1;i>1;i--) jcn[i]=1ll*(i+1)*jcn[i+1]%mod;
	for (int i=1;i<=n;i++){
		a[i] = read();
		if (lucky(a[i])) c[++sum] = a[i];
	}
	sort(c+1,c+1+sum);tot = 1;
	for (int i=1;i<=sum;i++){
		if (c[i]==c[i+1]) num[tot]++;
		else num[tot++]++;
	}
	tot--;
	f[0] = 1;
	for (int i=1;i<=tot;i++)
		for (int j=min(i,k);j;j--) 
			f[j] = (1ll*f[j-1]*num[i]+f[j])%mod;
	n-=sum;
	for (int i=0;i<=min(tot,k);i++) 
		ans = (1ll*f[i]*C(n,k-i)+ans)%mod;
	printf("%d",ans);
}
Category: codeforces | Tags: | Read Count: 842

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com