# hdu4734F(x)(dp)

http://acm.hdu.edu.cn/showproblem.php?pid=4734

 1 #include <iostream>
2 #include<cstdio>
3 #include<cstring>
4 #include<algorithm>
5 #include<stdlib.h>
6 #include<cmath>
7 using namespace std;
8 #define LL __int64
9 int dp[15][10500],dp2[15][10500];
10 int a,b;
11 int pp[20];
12 void init()
13 {
14     int i,j,g;
15     pp[0] = 1;
16     for(i = 1 ; i <= 11 ; i++)
17     pp[i] = pp[i-1]*2;
18     for(i = 0 ; i <= 9 ; i++)
19     dp[1][i] = 1;
20     for(i = 2 ; i <= 11 ; i++)
21     {
22         for(g = 0 ; g <= 9 ; g++)
23         {
24             for(j = 0 ; j <= 10054 ; j++)
25             {
26                 if(j+g*pp[i-1]>10054)
27                 continue;
28                 dp[i][j+pp[i-1]*g] += dp[i-1][j];
29             }
30         }
31     }
32     for(i = 1 ;  i <= 11 ; i++)
33     {
34         for(j = 1 ; j <= 10054 ; j++)
35         {
36             dp[i][j] += dp[i][j-1];
37         }
38     }
39 }
40 int fc(LL x)
41 {
42     int s=0,o=0;
43     while(x)
44     {
45         s+=(x%10)*pp[o];
46         x/=10;
47         o++;
48     }
49     return s;
50 }
51 int main()
52 {
53     int i,g,t,p[20],kk=0;
54     init();
55     scanf("%d",&t);
56     while(t--)
57     {
58         kk++;
59         scanf("%d%d",&a,&b);
60         int s1 = fc(a);
61         LL y = b;
62         int o=0;
63         while(y)
64         {
65             o++;
66             p[o] = y%10;
67             y/=10;
68         }
69         int ans=0;
70         int ts=0;
71         for(i = o ; i>= 1; i--)
72         {
73             for(g = 0 ; g < p[i] ; g++)
74             {
75                 int tt = ts+pp[i-1]*g;
76                 if(i==1)
77                 {
78                     if(tt<=s1)
79                     ans++;
80                     continue;
81                 }
82                 if(tt>s1)
83                 break;
84                 ans+=dp[i-1][s1-tt];
85             }
86             ts += p[i]*pp[i-1];
87         }
88         if(fc(b)<=s1)
89         ans++;
90         printf("Case #%d: ",kk);
91         printf("%d\n",ans);
92     }
93     return 0;
94 }
View Code

posted @ 2013-09-14 20:23 _雨 阅读(...) 评论(...) 编辑 收藏