不要62 HDU - 2089

 

不要62

 HDU - 2089 

杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer)。 
杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍,更安全地服务大众。 
不吉利的数字为所有含有4或62的号码。例如: 
62315 73418 88914 
都属于不吉利号码。但是,61152虽然含有6和2,但不是62连号,所以不属于不吉利数字之列。 
你的任务是,对于每次给出的一个牌照区间号,推断出交管局今次又要实际上给多少辆新的士车上牌照了。 

Input

输入的都是整数对n、m(0<n≤m<1000000),如果遇到都是0的整数对,则输入结束。 

Output

对于每个整数对,输出一个不含有不吉利数字的统计个数,该数值占一行位置。 

Sample Input

1 100
0 0

Sample Output

80
#include <iostream>
#include <algorithm>
#include <cstring> 
#include <cmath>
#include <string>
#include <cstdio>
using namespace std;

#define ll long long
#define CL(a, b) memset(a, b, sizeof(a))
const int N = 110;

int f[N][N]; //dp数组 
int a[N];

int dfs(int len, int pre, int state, bool limit) {
	// 当前位, 前一位,??, 是否限制状态
	if (len == 0) return 1;
	if (!limit && f[len][state] != -1) return f[len][state]; // 记忆化 
	int temp = 0;
	int up = limit? a[len] : 9; //当前位的上限取决于前一位是否取最大值 
	for (int i = 0; i <= up; ++i) {
		if (i == 4 || (i==2 && pre==6)) continue; //题目限制条件 
		temp += dfs(len-1, i, i == 6, limit&&i==a[len]);
	}
	if (!limit) f[len][state] = temp; //记忆化 
	return temp;
}

int count(int n) {
	
	int cnt = 0;
	CL(a, 0);
	while (n > 0) {
		a[++cnt] = n%10;
		n /= 10;
	}
	return dfs(cnt, -1, 0, true);
}


int main(){
	
	
	CL(f, -1);
	int n, m;
	while (~scanf ("%d %d", &n, &m) && (n+m)) {
		//memset(f, -1, sizeof(f));
		printf ("%d\n", count(m) - count(n-1));
		
	}
	
	
	
	return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章