HDU2089 ------不要62(數位dp)
阿新 • • 發佈:2017-08-10
判斷 tom name pop iostream blank 位置 play show
Total Submission(s): 26083 Accepted Submission(s): 9085
Sample Output
Author qianneng
Source 迎接新學期——超級Easy版熱身賽
Recommend lcy | We have carefully selected several similar problems for you:
不要62
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 26083 Accepted Submission(s): 9085
數位dp大法好!
。
杭州交通管理局常常會擴充一些的士車牌照,新近出來一個好消息,以後上牌照,不再含有不吉利的數字了。這樣一來,就能夠消除個別的士司機和乘客的心理障礙,更安全地服務大眾。
不吉利的數字為全部含有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
Author qianneng
Source 迎接新學期——超級Easy版熱身賽
Recommend lcy | We have carefully selected several similar problems for you:
pid=2094" target="_blank">2094 2090
pid=2091" target="_blank">2091 2093 2092
#include <iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<queue> #include<stack> #include<set> #include<map> #include<vector> #include<cctype> #define LL long long using namespace std; char s[12]; int C[12][12]; int bit[12]; int power[12]; int dp[10][11]; int wei(int n) { int k=0; while(n) { bit[++k]=n%10; n/=10; } return k; } void play_table() { memset(dp,0,sizeof(dp)); dp[0][0]=1; for(int i=1;i<=7;i++) { for(int j=0;j<=9;j++) //枚舉第i位的數字; { for(int k=0;k<=9;k++) //枚舉第i-1位的數字。 { if(j!=4&&!(j==6&&k==2)) dp[i][j]+=dp[i-1][k]; } } } } int solve(int n) { memset(bit,0,sizeof(bit)); int k=wei(n); int ans=0; for(int i=k;i>0;i--) { for(int j=0;j<bit[i];j++) { if(j!=4&&!(j==2&&bit[i+1]==6)) ans+=dp[i][j]; } if(bit[i]==4||(bit[i]==2&&bit[i+1]==6)) break; } return ans; } int main() { int m,n; play_table(); while(scanf("%d%d",&n,&m),m+n) { printf("%d\n", (solve(m+1)-solve(n))); } return 0; }
HDU2089 ------不要62(數位dp)