码迷,mamicode.com
首页 > 其他好文 > 详细

hdu4734 F(x)

时间:2019-06-10 21:15:11      阅读:95      评论:0      收藏:0      [点我收藏+]

标签:show   mem   event   har   output   class   for   const   pos   

技术图片
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5 const int maxn=1e5+5;
 6 int tot,e[15];
 7 int c[15][maxn];
 8 int t,a,b,cas;
 9 template<class t>void red(t &x)
10 {
11     int w=1;
12     x=0;
13     char ch=getchar();
14     while(ch>9||ch<0)
15     {
16         if(ch==-)
17             w=-1;
18         ch=getchar();
19     }
20     while(ch>=0&&ch<=9)
21     {
22         x=(x<<3)+(x<<1)+ch-0;
23         ch=getchar();
24     }
25     x*=w;
26 }
27 void input()
28 {
29     freopen("input.txt","r",stdin);
30     //freopen("output.txt","w",stdout);
31 }
32 void dv(int x)
33 {
34     tot=0;
35     while(x)
36     {
37         e[++tot]=x%10;
38         x/=10;
39     }
40     e[tot+1]=0;
41 }
42 int dfs(int pos,bool limit,int sum)
43 {
44     if(!pos)
45         return sum>=0;
46     if(sum<0)
47         return 0;
48     if(!limit&&c[pos][sum]!=-1)
49         return c[pos][sum];
50     int up=limit?e[pos]:9;
51     int ans=0;
52     for(int i=0;i<=up;++i)
53         ans+=dfs(pos-1,limit&&(i==up),sum-i*(1<<(pos-1)));
54     if(!limit)
55         c[pos][sum]=ans;
56     return ans;
57 }
58 int f(int x)
59 {
60     int ans=0,i=0;
61     while(x)
62     {
63         ans+=(1<<(i))*(x%10);
64         x/=10;
65         ++i;
66     }
67     return ans;
68 }
69 int solve()
70 {
71     //memset(c,-1,sizeof(c));
72     dv(b);
73     return dfs(tot,1,f(a));
74 }
75 int main()
76 {
77     //input();
78     red(t);
79     memset(c,-1,sizeof(c));
80     while(t--)
81     {
82         red(a);
83         red(b);
84         printf("Case #%d: %d\n",++cas,solve());
85     }
86     return 0;
87 }
View Code

 

hdu4734 F(x)

标签:show   mem   event   har   output   class   for   const   pos   

原文地址:https://www.cnblogs.com/Achensy/p/11000193.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!