[NOIP模拟][数位DP]准考证号
来源:互联网 发布:淘宝店铺怎么运营推广 编辑:程序博客网 时间:2024/04/28 19:20
题目描述:
CLC NOIP2015 惨跪,他依稀记得他的准考证号是 37(其实是假的),现在CLC又将要面临一场比赛,他希望准考证号不出现 37(连续),同时他又十分讨厌 4 ,所以也不希望 4 出现在准考证号中。现在他想知道在 A 和 B 之间有多少合法的准考证号
输入格式:
输入包含两个整数,A B。
输出格式:
输出一个整数。
样例输入1:
1 10
样例输出1:
9
样例输入 2:
25 50
样例输出2:
14
数据规模和约定:
20% 的数据,满足:1<=A<=B<=1000000 。
100% 的数据,满足:1<=A<=B<=2000000000 。
题目分析:
数位DP。也算是模板题,只要会数位DP,这道题就简单了。
附代码:
#include<iostream>#include<cstring>#include<string>#include<cstdlib>#include<cstdio>#include<ctime>#include<queue>#include<iomanip>#include<cmath>#include<cctype>#include<map>#include<set>#include<algorithm>using namespace std;int x,a[20],dp[20][5],ans;int dfs(int pos,int pre,int sta,int limit){ if(pos==0) return 1; if(limit==false&&dp[pos][sta]!=-1) return dp[pos][sta]; int up,tmp=0; if(limit==true) up=a[pos]; else up=9; for(int i=0;i<=up;i++) { if(pre==3&&i==7) continue; if(i==4) continue; tmp+=dfs(pos-1,i,i==3,limit&&i==a[pos]); } if(limit==false) dp[pos][sta]=tmp; return tmp;}int solve(int x){ memset(dp,-1,sizeof(dp)); int pos=0; while(x) { a[++pos]=x%10; x/=10; } return dfs(pos,-1,0,1);}int main(){ //freopen("ticket.in","r",stdin); //freopen("ticket.out","w",stdout); scanf("%d",&x); ans-=solve(x-1); scanf("%d",&x); ans+=solve(x); printf("%d",ans); return 0;}
阅读全文
2 0
- [NOIP模拟][数位DP]准考证号
- [NOIP模拟][数位DP]魔法数字
- [NOIP 模拟]潜水员 DP
- 【NOIp模拟】【dp】俄罗斯方块
- 【JZOJ5330】【NOIP提高组模拟】密码(库默尔定理、数位DP)
- NOIP模拟赛 数论 积性函数 + BSGS + Lucas模进制数位Dp
- [NOIP模拟题][DFS][DP]
- NOIP模拟题[dfs][DP]
- [NOIP模拟][状压DP]乘积
- NOIP模拟 探险 【树形dp】
- [NOIP模拟题][模拟][DP][乱搞]
- NOIP模拟题 [模拟][DP][线段树]
- 机房模拟赛 ccount Lucas+数位dp
- NOIP模拟题 LGTB 玩THD [DP]
- [noip模拟赛]祖先(dp)
- [noip模拟赛]二进制(dp)
- [noip模拟赛]敲砖块(dp)
- 【NOIP 模拟题】掷骰子(dp)
- Oracle 之 ORA-01847: day of month must be between 1 and last day of month
- --nodeps强制删除pcre后再安装报错
- curl模拟提交(post)
- 剑指offer:用两个栈实现队列
- 服务器搭建:servlet+dao+javabean+jsp实现简单的用户登录(一)
- [NOIP模拟][数位DP]准考证号
- 非极大值抑制(NMS)
- 数据结构之深度优先与广度优先算法
- MySQL Performance-Schema(一) 配置篇
- idea中代码不提示问题解决
- java身份证号码正则表达式校验
- 工作总结---检测认证(配置tomcat使用https)
- apply, call与bind方法
- 视音频资源(ffmpeg、opencv等)