标签:ace algo ott ber cstring main color script blog
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<algorithm> 5 using namespace std; 6 int f[20][14][4],bit[20],n,l; 7 int get(int a,int b){ 8 if(b==2)return 2; 9 return a==1?1:a==3&&b==1?2:0; 10 } 11 int dfs(int pos,int lim,int p,int is13){ 12 if(pos<=0&&p==0&&is13==2)return 1; 13 if(pos<=0)return 0; 14 if(!lim&&f[pos][p][is13]!=-1)return f[pos][p][is13]; 15 int rng=(lim?bit[pos]:9),ret=0; 16 for(int i=0;i<=rng;i++) 17 ret+=dfs(pos-1,lim&&(i==rng),(p*10+i)%13,get(i,is13)); 18 if(!lim)f[pos][p][is13]=ret; 19 return ret; 20 } 21 22 int main(){ 23 while(scanf("%d",&n)!=EOF){ 24 for(l=0;n;)bit[++l]=n%10,n/=10; 25 memset(f,-1,sizeof(f)); 26 printf("%d\n",dfs(l,1,0,0)); 27 } 28 }
标签:ace algo ott ber cstring main color script blog
原文地址:http://www.cnblogs.com/y-m-y/p/6663896.html