Codeforces Round #104 (Div. 1) C Lucky Subsequence

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #104 (Div. 1) C Lucky Subsequence相关的知识,希望对你有一定的参考价值。

?????????false   ?????????   round   c++   --   ??????   enc   turn   temp   

???????????????Lucky Subsequence

????????????????????????4???7??????????????????????????????????????? n ???????????????????????????????????? k ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????? 10^9 ????????????????????? 2^10=1024 ??????????????????????????????????????????????????????????????????????????? dp[i][j] ????????? i ???????????????????????? j ??????????????????????????????????????? dp[i][j]=dp[i-1][j]+dp[i-1][j-1]??num[i]????????? num[i] ?????? i ?????????????????????????????????????????????????????? ??dp[tot][j]??C(sum, k-j)???sum????????????????????????

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
const LL mod=1e9+7;

LL n,k,cnt,tot;
LL a[100005],b[100005],num[100005],fac[100005],dp[100005];

LL pow_mod(LL a,LL n){
    LL res=1,t=a;
    while(n){
        if(n&1) res=(res*t)%mod;
        t=(t*t)%mod;
        n/=2;
    }
    return res;
}
LL inv(LL x){
    return pow_mod(x,mod-2);
}
bool lucky(LL x){
    while(x){
        if(x%10!=4&&x%10!=7)
            return false;
        x/=10;
    }
    return true;
}
LL C(LL x,LL y){
    if(y==0) return 1;
    if(x<y) return 0;
    LL res=(fac[x]*inv(fac[y]))%mod;
    res=(res*inv(fac[x-y]))%mod;
    return res;
}

int main(){
    fac[0]=1;
    for(LL i=1;i<=100000;i++) fac[i]=(fac[i-1]*i)%mod;
    scanf("%lld%lld",&n,&k);
    for(LL i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        if(lucky(a[i])) b[++cnt]=a[i];
    }
    sort(b+1,b+1+cnt);
    LL sum=0;
    dp[0]=1;
    for(LL i=1;i<=cnt;i++){
        sum++;
        if(b[i]!=b[i+1]||i==cnt){
            tot++;
            for(LL j=tot;j>=1;j--){
                dp[j]=(dp[j]+dp[j-1]*sum%mod)%mod;
            }
            sum=0;
        }
    }
    LL ans=0;
    for(LL i=0;i<=k;i++){
        LL temp=dp[i]*C(n-cnt,k-i)%mod;
        ans=(ans+temp)%mod;
    }
    printf("%lld
",ans);

    return 0;
}

 

以上是关于Codeforces Round #104 (Div. 1) C Lucky Subsequence的主要内容,如果未能解决你的问题,请参考以下文章

Educational Codeforces Round 58 (Rated for Div. 2)(待更新)

[ACM]Codeforces Round #534 (Div. 2)

Codeforces Round #597 (Div. 2) A. Good ol' Numbers Coloring

Codeforces Round #723 (Div. 2) B. I Hate 1111(找规律,性质)

Codeforces Round #721 (Div. 2)ABC题解

Codeforces Round #721 (Div. 2)ABC题解