标签:
Time Limit: 1000/500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3384 Accepted Submission(s): 1271
#include <iostream> #include <cstring> #include <cmath> #include <cstdio> using namespace std; int dp[10][10240]; int bit[10]; int dfs(int len,int num,bool flag) //flag为1代表前位已选定,答案完整 { //否则答案还不完整 if(len==-1) return num>=0; if(num<0) return 0; if(!flag&&dp[len][num]!=-1) return dp[len][num]; int end=flag?bit[len]:9; int ans=0; for(int i=0;i<=end;i++) { ans+=dfs(len-1,num-(i*(pow(2,len))),flag&&i==end); } if(!flag) dp[len][num]=ans; return ans; } int F(int A) { int x=1; int ans=0; while(A) { ans+=(A%10)*x; x<<=1; A/=10; } return ans; } int cacu(int x,int A) { int top=0; while(x) { bit[top++]=x%10; x/=10; } return dfs(top-1,F(A),1); } int main() { int T,ca=1; memset(dp,-1,sizeof(dp)); for(scanf("%d",&T);T;T--) { int A,B; scanf("%d%d",&A,&B); printf("Case #%d: %d\n",ca++,cacu(B,A)); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zsyacm666666/p/5401831.html