标签:style color os strong io for
dp[i][j]表示i位数权值不超过j的数的个数
注意点:
dp[i][j]的值不用每次都初始化,因为它的值不受输入的影响,如果前面算过了就直接拿来用,没算过就拿来算并记录下来
<strong>#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<vector> #include<queue> #include<deque> #include<stack> #include<map> #include<set> #include<cmath> #include<cstdlib> #include<cctype> #define inf 0x3f3f3f3f #define maxn 10000 typedef long long LL; using namespace std; int m,n,pos,f[11],fa; int dp[11][5000]; int num[11]; int dfs(int pos,int s,int e) { if(s<0) return 0; if(pos==-1) return s>=0; if(!e&&dp[pos][s]!=-1) return dp[pos][s]; int end=e?num[pos]:9; int sum=0; for(int i=0;i<=end;i++){ sum+=dfs(pos-1,s-i*f[pos],e&&i==end); } return e?sum:dp[pos][s]=sum; } int main() { for(int i=0;i<=10;i++){ f[i]=1<<i; } int t,iCase=1; cin>>t; memset(dp,-1,sizeof dp); while(t--){ scanf("%d%d",&m,&n); int x=1,fa=0; while(m){ fa+=m%10*x; x<<=1; m/=10; } pos=0; while(n){ num[pos++]=n%10; n/=10; } printf("Case #%d: %d\n",iCase++,dfs(pos-1,fa,1)); } return 0; }</strong>
HDU4734——F(x)(数位DP),布布扣,bubuko.com
标签:style color os strong io for
原文地址:http://blog.csdn.net/u014141559/article/details/38070779