hdu_4734_F(x)(数位DP水)

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4734

题意:给你一个F(x)的定义,然后给你a,b,问你在0到b包括b有多少个数满足F(x)<=F(a)

题解:dp[i][j]为dp到第i位的和为j的方案

 1 #include<cstdio>
 2 #include<cstring>
 3 #define F(i,a,b) for(int i=a;i<=b;i++)
 4 
 5 int t,a,b,fa,dp[11][200001],ct,dig[11],len;
 6 
 7 int dfs(int pos,int sum,bool inf){
 8     if(!pos)return 1;
 9     if(!inf&&dp[pos][sum]!=-1)return dp[pos][sum];
10     int end=inf?dig[pos]:9,ans=0,tp;
11     F(i,0,end){
12         tp=sum-i*(1<<(pos-1));
13         if(tp>0)ans+=dfs(pos-1,tp,inf&&(i==end));
14     }
15     if(!inf)dp[pos][sum]=ans;
16     return ans;
17 }
18 
19 int main(){
20     scanf("%d",&t);
21     memset(dp,-1,sizeof(dp));
22     F(ic,1,t){
23         printf("Case #%d: ",ic);
24         scanf("%d%d",&a,&b);
25         for(fa=ct=0;a;a/=10,ct++)fa+=a%10*(1<<ct);
26         for(len=0;b;b/=10)dig[++len]=b%10;
27         printf("%d\n",dfs(len,fa+1,1));
28     }
29     return 0;
30 }
View Code

 



 

posted @ 2016-05-30 22:32  bin_gege  阅读(173)  评论(0编辑  收藏  举报