首页 > 代码库 > Little Elephant and Elections小象选举

Little Elephant and Elections小象选举

  在我正看着roll神的博客的时候发现了自己的错误

#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <climits>#include <string>#include <iostream>#include <map>#include <cstdlib>#include <list>#include <set>#include <queue>#include <stack>using namespace std;typedef long long LL;LL ans;const LL mod= 1000000007 ;LL dp[100][100];LL up[1000];LL Hash[100];LL dfs(LL now,LL sum,LL flag){    if(sum>ans) return 0;    if(now<=0) return sum==ans;    if(!flag&&~dp[now][sum]) return dp[now][sum];    LL limit= flag? up[now]:9,ret=0;    for(LL i = 0;i<= limit;i++){        if(i==4||i==7) ret+=dfs(now-1,sum+1,flag&&i==limit);        else ret+=dfs(now-1,sum,flag&&i==limit);    }    return flag? ret : dp[now][sum]=ret;}LL  solve(LL x){    LL len=0;    while(x){        up[++len]=x%10;        x/=10;    }    return dfs(len,0,1);}LL len;LL ans1=0;void gao(LL dep,LL left,LL w){    w%=mod;    if(dep==0){        ans1+=w;ans1%=mod;return ;    }    for(LL i= 0;i<=left;i++){        if(Hash[i])gao(dep-1,left-i,w*Hash[i]--),Hash[i]++;    }}int main(){    LL n;    cin>>n;    memset(Hash,0,sizeof(Hash));    for(ans=0 ;ans<10;ans++){        memset(dp,-1,sizeof(dp));//需要重新初始化。        Hash[ans]= solve(n) - solve(0);    }    len=10;    while(!Hash[len]) len--;    for(LL i = 1;i<=len;i++)        if(Hash[i])gao(6,i-1,Hash[i]);    cout<<ans1<<endl;    return 0;}