我是靠谱客的博主 合适蜻蜓,最近开发中收集的这篇文章主要介绍HDU3555 Bomb                 Bomb,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

                 Bomb

   Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)

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.
 
Solution:
    很裸的数位dp,记忆化搜索好啊,不过数组开小了,炸了几次。
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <algorithm>
 5 using namespace std;
 6 long long T,dp[105][15],bit[105];
 7 #define int long long
 8 long long n;
 9 long long dfs(int pos,int pre,bool Limit) {
10     if(pos<=0&&pre>=0) return 1;
11     if(pos<=0) return 0;
12     if(pre>=0&&!Limit&&dp[pos][pre]!=-1) return dp[pos][pre];
13     int End=Limit?bit[pos]:9;
14     long long ans=0;
15     for(int now,i=0; i<=End; ++i) {
16         if(pre==4&&i==9) continue;
17         now=i;
18         if(pre<0&&!i) now=pre;
19         ans+=dfs(pos-1,now,Limit&&(i==End));
20     } if(pre>=0&&!Limit) dp[pos][pre]=ans;
21     return ans;
22 }
23 signed main() {
24     //freopen("data.in","r",stdin);
25     //freopen("my.out","w",stdout);
26     scanf("%lld",&T);
27     for(int t=1; t<=T; ++t,bit[0]=0) {
28         memset(dp,0xff,sizeof(dp));
29         scanf("%lld",&n); 
30         long long x=n;
31         while(n) bit[++bit[0]]=n%10,n/=10;
32         printf("%lldn",x-dfs(bit[0],-10,true));
33     } return 0;
34 }

 

转载于:https://www.cnblogs.com/forevergoodboy/p/7766012.html

最后

以上就是合适蜻蜓为你收集整理的HDU3555 Bomb                 Bomb的全部内容,希望文章能够帮你解决HDU3555 Bomb                 Bomb所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(43)

评论列表共有 0 条评论

立即
投稿
返回
顶部