标签:des style blog io ar color os sp java
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2668 Accepted Submission(s): 1467
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int bit[15]; int dp[15][15][3]; int dfs(int pos,int s1,int s2,bool limit) //s1代表余数,s2代表状态 { if(pos==-1) { return (s1==0 && s2==2); } if(!limit && dp[pos][s1][s2]!=-1) return dp[pos][s1][s2]; int ans=0; int end=limit?bit[pos]:9; for(int i=0;i<=end;i++) { int nows2=0; if(s2==0) { if(i==1) nows2=1; } else if(s2==1) { if(i==1) nows2=1; else if(i==3) nows2=2; } else if(s2==2) nows2=2; ans+=dfs(pos-1,(s1*10+i)%13,nows2,limit && i==end); } if(!limit) dp[pos][s1][s2]=ans; return ans; } int cal(int n) { int len=0; while(n) { bit[len++]=n%10; n/=10; } return dfs(len-1,0,0,1); } int main() { int n; memset(dp,-1,sizeof(dp)); while(scanf("%d",&n)!=EOF) { printf("%d\n",cal(n)); } return 0; }
标签:des style blog io ar color os sp java
原文地址:http://www.cnblogs.com/hate13/p/4115398.html