不要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;
}

 

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