hdu 2089 不要62 【数位DP】
来源:互联网 发布:2015中国经济数据公布 编辑:程序博客网 时间:2024/06/05 04:58
#pragma comment(linker, "/STACK:102400000,102400000")
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <queue>
#define Pi acos(-1.0)
using namespace std;
typedef __int64 ll;
int DP[20][10];
int DIG[20];
int dfs(int pos,int pre,int limit)
{
if(pos < 0)
return 1;
if(!limit && DP[pos][pre] != -1)
return DP[pos][pre];
int end = limit ? DIG[pos] : 9;
int ret = 0;
for(int i = 0;i <= end;i ++){
if(i==4) continue;
if(pre==6 && i ==2 ) continue;
ret += dfs(pos - 1,i,limit && (i == end));
}
//DP里保存完整的、取到尽头的数据
if(!limit)
DP[pos][pre]= ret;
return ret;
}
int slove(int x){
memset(DP,-1,sizeof DP);
int num = 0;
while(x){
DIG[num] = x%10;
x/=10;
num++;
}
int ans = 0;
ans = dfs(num-1,0,1);
return ans;
}
int main(){
int n, m;
while(~scanf("%d%d", &n, &m)){
if(n==0 && m==0) break;
printf("%d\n", slove(m) - slove(n-1));
}
}
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <queue>
#define Pi acos(-1.0)
using namespace std;
typedef __int64 ll;
int DP[20][10];
int DIG[20];
int dfs(int pos,int pre,int limit)
{
if(pos < 0)
return 1;
if(!limit && DP[pos][pre] != -1)
return DP[pos][pre];
int end = limit ? DIG[pos] : 9;
int ret = 0;
for(int i = 0;i <= end;i ++){
if(i==4) continue;
if(pre==6 && i ==2 ) continue;
ret += dfs(pos - 1,i,limit && (i == end));
}
//DP里保存完整的、取到尽头的数据
if(!limit)
DP[pos][pre]= ret;
return ret;
}
int slove(int x){
memset(DP,-1,sizeof DP);
int num = 0;
while(x){
DIG[num] = x%10;
x/=10;
num++;
}
int ans = 0;
ans = dfs(num-1,0,1);
return ans;
}
int main(){
int n, m;
while(~scanf("%d%d", &n, &m)){
if(n==0 && m==0) break;
printf("%d\n", slove(m) - slove(n-1));
}
}
0 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
- 【数位DP】【HDU 2089】不要62
- hdu 2089 不要62(数位DP)
- hdu 2089 不要62 --- 数位dp
- 数位DP小记 + HDU 2089 不要62
- HDU 2089 不要62(数位dp)
- 数位 dp HDU 2089 不要62
- HDU 2089 不要62(数位DP)
- hdu 2089 不要62--数位dp入门
- AVL树
- 第四周项目3-单链表应用(3)
- XML笔记-XML基础
- 二叉树中的度
- API性能测试基本性能指标及要求
- hdu 2089 不要62 【数位DP】
- github版本托管
- bzoj1616(搜索)
- BZOJ1096: [ZJOI2007]仓库建设 斜率优化DP
- HDU 5893 List wants to travel 树链剖分 边权剖分
- 《MySQL必知必会》读书笔记(一)
- DECODE ROUND case when
- java程序设计之集合中迭代器的使用
- 从现在开始丰富自己的简历