题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555

Bomb

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

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.

题解:

数位DP通用:dp[pos][sta1][sta2][……]

表示:当前位为pos,之前的状态为sta1*sta2*……stan。n为限制条件的个数。

回到此题,限制条件有两个: 1.上一位是否为4; 2.之前是否已经出现49。

类似题目:http://blog.csdn.net/dolfamingo/article/details/72848001

代码如下:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
using namespace std;
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+;
const int maxn = +; LL n;
LL a[maxn], dp[maxn][]; LL dfs(int pos, int status, bool lim)
{
if(!pos) return status==;
if(!lim && dp[pos][status]!=-) return dp[pos][status]; LL ret = ;
int m = lim?a[pos]:;
for(int i = ; i<=m; i++)
{
int tmp_status;
if(status== || status== && i==)
tmp_status = ;
else if(i==)
tmp_status = ;
else
tmp_status = ; ret += dfs(pos-, tmp_status, lim&&(i==m));
} if(!lim) dp[pos][status] = ret;
return ret;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lld",&n);
int p = ;
while(n)
{
a[++p] = n%;
n /= ;
}
memset(dp,-, sizeof(dp));
LL ans = dfs(p, , );
printf("%lld\n",ans);
}
}

HDU3555 Bomb —— 数位DP的更多相关文章

  1. hdu---(3555)Bomb(数位dp(入门))

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submi ...

  2. hdu3555 Bomb(数位dp)

    题目传送门 Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total ...

  3. hdu3555 Bomb 数位DP入门

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 简单的数位DP入门题目 思路和hdu2089基本一样 直接贴代码了,代码里有详细的注释 代码: ...

  4. HDU3555 Bomb[数位DP]

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submi ...

  5. HDU3555 Bomb 数位DP第一题

    The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the ti ...

  6. hdu3555 Bomb (数位dp入门题)

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submi ...

  7. 【hdu3555】Bomb 数位dp

    题目描述 求 1~N 内包含数位串 “49” 的数的个数. 输入 The first line of input consists of an integer T (1 <= T <= 1 ...

  8. HDU 3555 Bomb 数位dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Mem ...

  9. hud 3555 Bomb 数位dp

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Subm ...

随机推荐

  1. C 语言中的 fgets()

    转自:http://blog.csdn.net/daiyutage/article/details/8540932 原型: char *  fgets(char * s, int n,FILE *st ...

  2. POJ 3099 Go Go Gorelians

    http://poj.org/problem?id=3099 树的重心:找到一个点,其所有的子树中最大的子树节点数最少,那么这个点就是这棵树的重心 求树的重心 如何在点中构造符合条件的树 得到树后 从 ...

  3. 在GridView中的每一页末尾添加空行

    原文发布时间为:2008-08-03 -- 来源于本人的百度文章 [由搬家工具导入] protected void GridView1_RowCreated(object sender, GridVi ...

  4. Tengine的concat模块与js、css合并

    首先,先走出一个误区 ,下面是tengine-cn邮件列表里的一篇邮件原文:“看了这个例子就了解了,这个所谓的合并请求只是把所有的CSS或JAVASCRIPT请求合并,必须是同一个文件类型的.我开始想 ...

  5. php——离线执行任务

    <?php//设置忽略是否关闭终端窗口ignore_user_abort(true);ini_set('max_execution_time', '0');//采集页面函数,看不懂执行百度cur ...

  6. 某考试 T1 function

    (数据范围 n<=10^9 ,T<=10 ) 首先,我来证明一下 Σμ(d) * σ(i/d)^2 = σ(i^2) 相信做过约数个数和的童鞋都可以完成从右式推到左式,那么我现在就说一下怎 ...

  7. docker日志输出文件大小设置以及文件个数限制

    问题描述: 今天有同事运行了一个docker容器,不多时就导致宿主机硬盘直接撑爆,消耗了120G,发生的很是突然. 问题排查: 后续查阅资料,发现是因为docker中的某个进程一直在持续输出,而这些输 ...

  8. BUPT复试专题—最近公共祖先(2014软院)

    题目描述 给出一棵有N个节点的有根树TREE(根的编号为1),对于每组查询,请输出树上节点u和v的最近公共祖先. 最近公共祖先:对于有向树TREE的两个结点u,v.最近公共祖先LCA(TREE u,v ...

  9. 转:我们是怎么做Code Review的

    我们是怎么做Code Review的   前几天看了<Code Review 程序员的寄望与哀伤>,想到我们团队开展Code Review也有2年了,结果还算比较满意,有些经验应该可以和大 ...

  10. 系统重装 WIN7如何创建和使用VHD文件

    1 在磁盘管理中,点击操作-创建VHD,然后可以创建一个空的VHD文件   2 右击这个磁盘,点击初始化磁盘,然后可以新建简单卷   3 右击这个磁盘,设置为脱机或者联机就可以在计算机中显示和隐藏这个 ...