hdu2089 不要62 数位DP模板题
2014-08-08 21:57
357 查看
算是学习数位dp的入门题。。。
具体看代码中注释
具体看代码中注释
#include <cstdio> #include <string> #include <cstring> #include <iostream> #include <algorithm> #include <vector> #define maxn 30 using namespace std; int limit[40];//存储数字的各位值 int dp[40][10]; int dfs(int now,int prev,bool flag) { if(now<=0) return 1; if(!flag&&dp[now][prev]!=-1) return dp[now][prev]; //记忆化搜索 int bound=flag?limit[now]:9,ret=0; //如果此时为边界,则bound最大值为limit[now] for(int k=0;k<=bound;k++) { if(k==4) continue; if(k==2&&prev==1) continue; ret+=dfs(now-1,k==6,flag&&(k==bound)); } if(!flag) dp[now][prev]=ret; return ret; } int count(int x) { int len=0; while(x) { limit[++len]=x%10;//将x的各位用limit数组保存 x/=10; } return dfs(len,0,true); } int main() { int n,m; memset(dp,-1,sizeof(dp)); while(cin>>n>>m) { if(n==0&&m==0) break; cout<<count(m)-count(n-1)<<endl; } return 0; }
相关文章推荐
- hdu2089 不要62 数位dp模板
- hdu2089 不要62(数位dp模板)
- HDU 2089 不要62(数位DP入门+模板)
- [hdu2089]不要62(数位dp)
- hdoj 2089 不要62(数位dp入门模板)
- hdu2089——不要62(数位dp)
- HDU-2089 不要62 数位DP 模板题
- HDU 2089 不要62(数位DP入门+模板)
- 【数位DP】 hdu2089 不要62
- [HDU2089] 不要62 && 数位DP
- HDU 2089 不要62(数位DP入门+模板)
- HDU2089 不要62(数位DP)
- HDU2089:不要62(数位DP)
- 【数位DP】HDU2089-不要62
- 【数位DP】【HDU2089】不要62
- hdu2089 不要62 (数位DP)
- ☆ [HDU2089] 不要62「数位DP」
- hdu2089 不要62(数位dp)
- HDU 2089 不要62(数位DP入门+模板)
- 【数位DP】【HDU2089】不要62