hdu 3555 Bomb ( 数位DP)
Bomb
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 7926 Accepted Submission(s): 2780
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?
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[i][1]表示不含49且高位为9的个数;
dp[i][2]表示包括49的个数;
dp[i][0]=10*dp[i-1][0]-dp[i-1][1]; //不含49的数能够随意加10个数字。减去9前面加4的个数
dp[i][1]=dp[i-1][0]; //不含49的数最高位加9
dp[i][2]=dp[i-1][2]*10+dp[i-1][i]; //包括49的数字能够加入0~9,高位为9的能够加4;
#include"stdio.h"
#include"string.h"
#include"iostream"
#include"algorithm"
#include"math.h"
#include"vector"
using namespace std;
#define LL __int64
#define N 25
LL dp[N][3];
void inti()
{
memset(dp,0,sizeof(dp));
dp[0][0]=1;
int i;
for(i=1; i<N; i++)
{
dp[i][0]=dp[i-1][0]*10-dp[i-1][1];
dp[i][1]=dp[i-1][0];
dp[i][2]=dp[i-1][2]*10+dp[i-1][1];
}
}
LL work(LL x)
{
int i,k,flag;
int a[N];
LL ans;
k=0;
while(x)
{
a[++k]=x%10;
x/=10;
}
a[k+1]=ans=flag=0;
for(i=k; i>0; i--)
{
ans+=a[i]*dp[i-1][2];
if(flag)
ans+=a[i]*dp[i-1][0];
else
{
if(a[i]>4)
ans+=dp[i-1][1];
}
if(a[i+1]==4&&a[i]==9)
flag=1;
// printf("%d\n",ans);
}
return ans;
}
int main()
{
int T;
LL n;
inti();
scanf("%d",&T);
while(T--)
{
scanf("%I64d",&n);
printf("%I64d\n",work(n+1));
}
return 0;
}
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 ...
随机推荐
- Java实现简单计算器、抽票程序
计算器: import java.awt.BorderLayout; import java.awt.Container; import java.awt.Font; import java.awt. ...
- UVA 1592 DataBase
思路: 知识补充: ①make_pair和pair: /*pair是将2个数据组合成一个数据,当需要这样的需求时就可以使用pair,如stl中的map就是将key和value放在一起来保存.另一个应用 ...
- VMware5.5-高可用性和动态资源调度(DRS)
高可用性 故障分类:ESX主机---虚拟机(主机通过vmtools监控)---应用程序(基本不用6.0新增了这一功能) 高可用的信号检测目前可分为两种 一.网络信号 二.存储信号 新建群集 上图的自定 ...
- 2018-6-20-随笔-SQL Server中乱码
SQL Server中乱码解决方案: 在Sql Server2005英文版中,如果未对Varchar类型的字段进行设置,那么很多朋友会发现向数据库中插入记录时,如果对应的varchar类型字段 的值为 ...
- 什么是OKR?
什么是OKR OKR全称是Objectives and Key Results,即目标与关键成果法.OKR是一套定义和跟踪目标及其完成情况的管理工具和方法.1999年 Intel公司发明了这种方法,后 ...
- CentOS6.5使用rsync远程同步
需达成目标:在服务器(192.168.18.211)端搭建 rsync 服务, 将 /root/rsync-server/ 目录同步到客户端 /root/rsync-local 目录 Li ...
- video设置视频的宽高
一般情况下<video loop="loop" style="width: 100%;height:300px;" controls="cont ...
- Charles抓包(未完待续)
Charles是在 Mac 下常用的网络封包截取工具,在做移动开发时,我们为了调试与服务器端的网络通讯协议,常常需要截取网络封包来分析. Charles 通过将自己设置成系统的网络访问代理服务器,使得 ...
- jmeter接口测试实例6-注册(参数化)
Jmeter实例6:注册(参数化) 选中http协议,添加CSV Data set Config 准备参数中要使用到的值,存放到txt中,如果一个里面有多个参数,中间用,号分隔: 选中CSV元件,fi ...
- 部署前准备--使用Mysql之Django Debug Toolbar安装以及配置
python -c "import django ;print(django.__path__);" 查看python的全局配置 vi /usr/local/lib/python3 ...