/ Randle /

记录详情

Accepted


  
# 状态 耗时 内存占用
#1 Accepted 2ms 444.0 KiB
#2 Accepted 2ms 2.301 MiB
#3 Accepted 1ms 312.0 KiB
#4 Accepted 1ms 324.0 KiB
#5 Accepted 3ms 2.426 MiB
#6 Accepted 2ms 2.426 MiB
#7 Accepted 4ms 2.438 MiB
#8 Accepted 26ms 8.805 MiB
#9 Accepted 63ms 11.551 MiB
#10 Accepted 95ms 9.312 MiB

代码

#include<iostream>
#include<map>
#define maxn 100001
using namespace std;
typedef long long ll;
int P=1000000007;
int d=0,ans=0,tot=0,fact[maxn],nn,k,c[maxn],dp[2001][2001];
map<int,int>mp;
int fast(int a,int b)
{
	int rest=1;
	while(b)
	{
		if(b%2==1)
		rest=1ll*rest*a%P;
		a=1ll*a*a%P;
		b/=2;
	}
	return rest;
}
bool check(int x)
{
	if(x==0)
	return false;
	while(x)
	{
		int t=x%10;
		if(t!=4&&t!=7)
		return false;
		x=x/10;
	}
	return true;
}
int cale(int n,int m)
{
	if(n>m)
	return 0;
	return 1ll*fact[m]%P*fast(fact[n],P-2)%P*fast(fact[m-n],P-2)%P;
}
int main()
{
	//freopen("lucky.in.txt","r",stdin);
	//freopen("lucky.out.txt","w",stdout);
    int x;
    cin>>nn>>k;
    for(int i=1;i<=nn;i++)
    {
    	cin>>x;
    	if(check(x))
    		mp[x]++;
		else d++;
    }
	fact[0]=1;
	for(int i=1;i<=nn;i++)
		fact[i]=1LL*fact[i-1]*i%P;
	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++)
		c[++tot]=it->second;
	for(int i=0;i<=tot;i++)
		dp[i][0]=1;
	for(int i=1;i<=tot;i++)
		for(int j=1;j<=i;j++)
		{
			dp[i][j]=(dp[i][j]+dp[i-1][j])%P;
			dp[i][j]=(dp[i][j]+1ll*dp[i-1][j-1]*c[i])%P;
		}
	for(int i=0;i<=min(tot,k);i++)
		ans=(ans+1ll*dp[tot][i]*cale(k-i,d))%P;
	cout<<ans<<endl;
	return 0;
}

信息

递交者
类型
递交
题目
幸运数 T3
题目数据
下载
语言
C++
递交时间
2017-09-15 20:28:34
评测时间
2017-10-01 16:12:37
评测机
分数
100
总耗时
205ms
峰值内存
11.551 MiB