HDU 3555 Bomb(数位DP)
Bomb
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 11804 Accepted Submission(s): 4212
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?
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.
1
50
500
1
15
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。
预处理:
f[i][0] 表示i位数中不含49的数的数目
f[i][1] 表示i位数中不含49且最高位为9的数的数目
f[i][2] 表示i位数中含49的数的数目
根据n的每一位统计ans,具体见代码。
【代码】
#include<cstdio>
using namespace std; typedef long long LL;
LL f[][];
/*
f[i][0] i位数 无49存在
f[i][1] i位数 无49存在且末尾为9
f[i][2] i位数 有49
*/
int b[]; void init() {
f[][]=; f[][]=f[][]=;
for(int i=;i<;i++) {
f[i][]=*f[i-][]-f[i-][];
f[i][]=f[i-][];
f[i][]=*f[i-][]+f[i-][];
}
} int main() {
int T; LL n;
scanf("%d",&T);
init();
while(T--) {
scanf("%I64d",&n);
int len=;
while(n)
b[++len]=n% , n/=;
b[len+]=;
LL ans=; bool flag=;
for(int i=len;i;i--) {
ans += b[i]*f[i-][]; // + ...49...
if(flag) ans += f[i-][]*b[i]; // + 49...(无49...)
else if(b[i]>) ans += f[i-][]; // + 4(9 无49)
if(b[i+]== && b[i]==) flag=;
}
if(flag) ans++; //算上自身
printf("%I64d\n",ans);
}
return ;
}
HDU 3555 Bomb(数位DP)的更多相关文章
- HDU 3555 Bomb 数位dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Mem ...
- HDU 3555 Bomb 数位DP 入门
给出n,问所有[0,n]区间内的数中,不含有49的数的个数 数位dp,记忆化搜索 dfs(int pos,bool pre,bool flag,bool e) pos:当前要枚举的位置 pre:当前要 ...
- HDU - 3555 - Bomb(数位DP)
链接: https://vjudge.net/problem/HDU-3555 题意: The counter-terrorists found a time bomb in the dust. Bu ...
- Bomb HDU - 3555 (数位DP)
Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terro ...
- HDU(3555),数位DP
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others ...
- HDU 3555 Bomb (数位DP-记忆化搜索模板)
题意 求区间[1,n]内含有相邻49的数. 思路 比较简单的按位DP思路.这是第一次学习记忆化搜索式的数位DP,确实比递推形式的更好理解呐,而且也更通用~可以一般化: [数位DP模板总结] int d ...
- hud 3555 Bomb 数位dp
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Subm ...
- hdoj 3555 BOMB(数位dp)
//hdoj 3555 //2013-06-27-16.53 #include <stdio.h> #include <string.h> __int64 dp[21][3], ...
- 数位DP入门之hdu 3555 Bomb
hdu 3555 Bomb 题意: 在1~N(1<=N<=2^63-1)范围内找出含有 ‘49’的数的个数: 与hdu 2089 不要62的区别:2089是找不不含 '4'和 '62'的区 ...
- HDU 3555 Bomb(数位DP模板啊两种形式)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 Problem Description The counter-terrorists found ...
随机推荐
- .NET设计模式(9):桥接模式(Bridge Pattern)
.NET设计模式(9):桥接模式(Bridge Pattern) 桥接模式(Bridge Pattern) --.NET设计模式系列之九 年月 实现代码如下:..所谓抽象和实现沿着各自维度的变 ...
- CoreAnimation2-视觉效果和变换
圆角 圆角矩形是iOS的一个标志性审美特性.这在iOS的每一个地方都得到了体现,不论是主屏幕图标,还是警告弹框,甚至是文本框.按照这流行程度,你可能会认为一定有不借助Photoshop就能轻易创建圆角 ...
- 批量翻转PNG图片
用了好几个软件都不好用. 要么不能翻转PNG, 要么翻转之后没有透明度了. 基本上全是图形界面, 要鼠标批量拖放. 所以, 还是自己动手, 写一个批量png翻转工具. #include <ios ...
- Binary Tree Level Order Traversal II 解题思路
思路: 与Binary Tree Level Order Traversal I 几乎一样.只是最后将结果存放在栈里,然后在栈里再传给向量即可. 再次总结思路: 两个queue,先把第一个放进q1,循 ...
- js中的prototye
前言 没事的时候写着js完,一般可能大家都知道这个属性吧,但是我还要说说,给一些不知道的人看看吧, 希望对你有帮助. 过程 以前在学c#的时候,老师最多用的就是Person这个类来开讲,我觉得是这个更 ...
- 解决SDK Manager无法更新问题
因为google被封了,导致Android SDK Manager无法更新,解决方案如下: 1.选择tools->options,跳出Settings页面 2.设置HTTP Proxy代理,设置 ...
- 设置服务器远程连接mysql
一直单人开发所以没有考虑过这方面,到新公司要做合作开发,所以要进行设置,然后开始自己搞 下面把过程罗列一下: 1)由于使用的云服务器 ,所以上面都配置好了,直接配置了mysql的命令行输入密码就可以进 ...
- quick-x 触摸事件的新方法
--[[ local function onTouch(event, x, y) print(event, x, y) if event == "began" then retur ...
- Winbind authentication against active directory
Winbind authentication against active directory Description This tip will describe how to configure ...
- Maya pywin32
Maya 2011 – 2013 64-bit: maya-64-bit-pywin32.zipMaya 2011 – 2013 32-bit: maya-32-bit-pywin32.zipMaya ...