hdoj 2089 不要62
来源:互联网 发布:合肥市行知学校在哪 编辑:程序博客网 时间:2024/06/06 13:20
题目链接:不要62
题目大意:给你一个区间,问这个区间里面符合条件的个数有多少,条件是不能出现62连号或者出现4
题目思路:直接数位dp就好,还不需要判断前导0的情况
#include <map>#include <set>#include <queue>#include <stack>#include <cmath>#include <vector>#include <cstdio>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>using namespace std;int a[20],dp[20][2];int dfs(int pos,int pre,int sta,bool limit){ if(pos == -1) return 1; if(!limit&&dp[pos][sta] != -1) return dp[pos][sta]; int up = limit?a[pos]:9; int tmp = 0; for(int i = 0;i <= up;i++){ if(pre == 6&&i == 2||i == 4) continue; tmp += dfs(pos-1,i,i == 6,limit&&i == a[pos]); } if(!limit) dp[pos][sta] = tmp; return tmp;}int solve(int x){ int pos = 0; while(x){ a[pos++] = x%10; x/=10; } return dfs(pos-1,-1,0,true);}int main(){ int le,ri; while(~scanf("%d%d",&le,&ri)&&le+ri){ memset(dp,-1,sizeof(dp)); printf("%d\n",solve(ri)-solve(le-1)); } return 0;}
阅读全文
0 0
- HDOJ 2089 不要62
- HDOJ 2089 不要62
- hdoj 2089 不要62
- HDOJ 2089 不要62
- 不要62 hdoj 2089
- HDOJ 2089 不要62
- HDOJ 2089 不要62
- hdoj 2089 不要62
- HDOJ 2089 不要62
- 【HDOJ 2089】不要62
- HDOJ--2089--不要62
- hdoj-2089-不要62
- HDOJ-2089 不要62
- HDOJ 2089 不要62
- hdoj 2089 不要62
- HDOJ 2089 不要62
- hdoj-【2089 不要62】
- HDOJ.2089 不要62
- Java基础
- DWURunLoopWorkDistribution源码解读
- java线程:Atomic(原子的)
- spring 中常用的两种事务配置方式以及事务的传播性、隔离级别
- Python学习记录——常用的IO操作及代替批处理命令
- hdoj 2089 不要62
- 取两张mysql表中分别两个字段相同的值
- 并查集入门--知识点 畅通工程
- spring Aop 配置异常问题
- 极性与非极性电容并联的作用
- windows storm 1.1.1启动失败解决
- MySQL集群搭建详解
- Spring容器中init Bean和destroy Bean的方式
- HDU 6152 Friend-Graph