HDU 2089 不要62(数位 dp)
2014-09-10 23:16
363 查看
http://acm.hdu.edu.cn/showproblem.php?pid=2089
思路:用·dp【i】记录位数<=i+1的满足条件数字个数,搜索时是从最高位向最低位搜索的,搜索有一定条件,注意细节,很具有代表性的题目。
代码:
思路:用·dp【i】记录位数<=i+1的满足条件数字个数,搜索时是从最高位向最低位搜索的,搜索有一定条件,注意细节,很具有代表性的题目。
代码:
#include<iostream> #include<cstdio> #include<cmath> #include<map> #include<stack> #include<set> #include<cstring> #include<algorithm> #define LL long long #define MOD 100000007 #define INF 0x3f3f3f3f using namespace std; const int maxn=100; int l,r,dp[maxn],digit[maxn]; int dfs(int cur,bool limit,bool pre_six) { if(cur==-1)return 1; if(!limit&&!pre_six&&dp[cur]!=-1)return dp[cur]; int tail=limit?digit[cur]:9; int ans =0; for(int i=0;i<=tail;i++) if(i!=4&&(!pre_six||i!=2)) ans+=dfs(cur-1,limit&&i==tail,i==6); if(!limit&&!pre_six)dp[cur]=ans; return ans; } int scan(int x) { int cur=0; while(x) { digit[cur++]=x%10; x/=10; } return cur-1; } int main() { memset(dp,-1,sizeof dp); while(~scanf("%d%d",&l,&r)&&(l||r)) { int n=scan(r); int ans=dfs(n,true,false); n=scan(max(0,l-1)); ans-=dfs(n,true,false); printf("%d\n",ans); } return 0; }
相关文章推荐
- HDU 2089 不要62 还是基础数位dp
- hdu 2089(不要62)数位DP
- HDU-2089 不要62 数位DP 模板题
- HDU - 2089 不要62 (暴力或数位DP)
- hdu 2089 不要62--数位dp入门
- hdu 2089 不要62 数位DP
- HDU 2089:不要62(数位DP)
- HDU 2089 不要62(数位dp)
- HDU 2089 不要62(数位DP)
- [HDU 2089]不要62[数位DP]
- hdu 2089 不要62(数位dp)
- hdu 2089 不要62 hdu 3555 Bomb (数位DP)
- HDU 2089 不要62 数位dp入门
- hdu 2089 不要62--数位dp入门
- HDU 2089 不要62(数位DP)
- hdu 2089 不要62(数位DP)
- hdu 2089 不要62 --- 数位dp
- HDU 2089——不要62(数位DP)
- hdu 2089 不要62 数位dp
- HDU 2089 不要62(数位DP入门)