hdu---(3555)Bomb(数位dp(入门))
Bomb
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 7921 Accepted Submission(s): 2778
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.

//#define LOCAL
#include<cstdio>
#include<cstring>
#define LL __int64
using namespace std;
const int maxn=;
LL dp[maxn][]={};
int nn[maxn];
int main()
{ #ifdef LOCAL
freopen("test.in","r",stdin);
#endif
int cas,i;
LL n;
scanf("%d",&cas);
/*数位DP的惯有模式预处理*/
dp[][]=;
for(i=;i<=;i++)
{
dp[i][]=dp[i-][]*-dp[i-][];
dp[i][]=dp[i-][];
dp[i][]=dp[i-][]*+dp[i-][];
}
while(cas--)
{
scanf("%I64d",&n);
i=;
n+=;
memset(nn,,sizeof(nn));
while(n>)
{
nn[++i]=n%;
n/=;
}
LL ans=;
bool tag=;
int num=;
for( ; i>= ; i-- )
{
ans+=dp[i-][]*nn[i]; /*计算49开头的个数*/
if(tag){
ans+=dp[i-][]*nn[i]; /*当前面出现了49的时候,那么后面出现的任何数字也要进行统计*/
}
if(!tag&&nn[i]>)
{
ans+=dp[i-][]; /*如果没有出现49开头,只要首部大于5,那么必定保函有一个49*/
}
if(num==&&nn[i]==)
tag=;
num=nn[i];
}
printf("%I64d\n",ans);
}
return ;
}
hdu---(3555)Bomb(数位dp(入门))的更多相关文章
- HDU 3555 Bomb 数位DP 入门
给出n,问所有[0,n]区间内的数中,不含有49的数的个数 数位dp,记忆化搜索 dfs(int pos,bool pre,bool flag,bool e) pos:当前要枚举的位置 pre:当前要 ...
- 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)
链接: 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 ...
- hdu3555 Bomb 数位DP入门
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 简单的数位DP入门题目 思路和hdu2089基本一样 直接贴代码了,代码里有详细的注释 代码: ...
- 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题
[HDU 3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...
- 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], ...
随机推荐
- UVA 1456 六 Cellular Network
Cellular Network Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit S ...
- vb6.0安装程序制作图解教程
如何制作vb安装程序,是在学习Vb6.0过程中比较常见的一个入门问题. 在此笔者介绍一个最简单的安装方法,就是用VB自带的打包程序进行打包,虽然比较普通,不过内部却有不少窍门,相信这一点知道的人可能不 ...
- python_way day12 RabbitMQ ,pymysql
python_way day12 1.RabbitMQ 2.pymysql RabbitMQ 1.基本用法 """ producer """ ...
- C#TextBox自动滚动到最低端
C#中一个RichTextBox,当新写入内容时,超过当前显示区域后,自动滚动到最低端,方便查看内容. private void txtInfo_TextChanged(object sender, ...
- Entity Framework 学习初级篇--EntityClient(转)
摘自:http://www.cnblogs.com/xray2005/archive/2009/05/13/1456374.html System.Data.EntityClient 命名空间是 实体 ...
- GIMP学习笔记
参考文献: ① http://www.gimp.org/docs/userfaq.html GIMP是GNU Image Manipulation Program的缩写,sired by Spence ...
- adb_常用命令
1. adb push 电脑中的文件(包含路径) Android中的绝对路径 2. adb pull Android中的绝对路径文件 电脑中的绝对路径 3. adb install ??.ap ...
- chrome离线安装包_下载
ZC: 如何下载的文章 参考:“https://www.tekrevue.com/tip/download-chrome-offline-installer/” 1. f/q 2.下载网址: 2.1. ...
- [转载] 深入理解 docker ulimit
深入理解docker ulimit 2015年7月23日 10:00 阅读 12778 [编者的话]Docker大规模应用后,如果你没踩过坑,说出去肯定没人信.昨天就遇到一个ulimit的经典问题:业 ...
- Json知识总结
JSON对象是一个无序的"名称/值"对的集合它开始于“{”,结束于“}”.每一个属性名和值间用“:”提示,属性间用“,”分隔.一个数组开始于"[",结束于&qu ...