码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 3555 Bomb

时间:2015-09-04 19:47:39      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:

Bomb

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 10967    Accepted Submission(s): 3890


Problem Description
The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the time bomb. The number sequence of the time bomb counts from 1 to N. If the current number sequence includes the sub-sequence "49", the power of the blast would add one point.
Now the counter-terrorist knows the number N. They want to know the final points of the power. Can you help them?
 

 

Input
The first line of input consists of an integer T (1 <= T <= 10000), indicating the number of test cases. For each test case, there will be an integer N (1 <= N <= 2^63-1) as the description.

The input terminates by end of file marker.
 

 

Output
For each test case, output an integer indicating the final points of the power.
 

 

Sample Input
3
1
50
500
 

 

Sample Output
0
1
15
 
Hint
From 1 to 500, the numbers that include the sub-sequence "49" are "49","149","249","349","449","490","491","492","493","494","495","496","497","498","499", so the answer is 15.
 

 

Author
fatboy_cw@WHU
 

 

Source
 
解题:数位dp,我就不说什么了
 
技术分享
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const int maxn = 21;
 5 LL dp[maxn][3];
 6 int b[maxn];
 7 LL dfs(int p,int st,bool flag){
 8     if(!p) return st == 2;
 9     if(flag && dp[p][st] != -1) return dp[p][st];
10     int u = flag?9:b[p];
11     LL ret = 0;
12     for(int i = 0; i <= u; ++i){
13         if(st == 1 && i == 9 || st == 2) ret += dfs(p-1,2,flag||(i < u));
14         else if(i == 4) ret += dfs(p-1,1,flag||(i < u));
15         else ret += dfs(p-1,0,flag||(i < u));
16     }
17     if(flag) dp[p][st] = ret;
18     return ret;
19 }
20 LL solve(LL x){
21     int len = 0;
22     while(x){
23         b[++len] = x%10;
24         x /= 10;
25     }
26     return dfs(len,0,false);
27 }
28 int main(){
29     memset(dp,-1,sizeof dp);
30     int kase;
31     scanf("%d",&kase);
32     while(kase--){
33         LL tmp;
34         scanf("%I64d",&tmp);
35         printf("%I64d\n",solve(tmp));
36     }
37     return 0;
38 }
View Code

 

HDU 3555 Bomb

标签:

原文地址:http://www.cnblogs.com/crackpotisback/p/4782213.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!