O-Bomb(数位dp)
Bomb
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 15062 Accepted Submission(s):
5437
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?
<= 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.
final points of the power.
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.
#include <stdio.h>
#include <string.h> __int64 dp[][];
//dp[i][0] 含49,数的个数
//dp[i][1] 不含49,但首位是9的数的个数
//dp[i][2] 不含49,数的个数(包含了首位是9的数的个数)
void Init()
{
dp[][]=;
for (int i=;i<=;i++)
{
dp[i][]=dp[i-][]*+dp[i-][];
dp[i][]=dp[i-][];
dp[i][]=dp[i-][]*-dp[i-][];
}
} __int64 solve(__int64 n)
{
__int64 a[],len=; while (n)
{
a[++len]=n%;
n/=;
}
a[len+]=; __int64 ans=;
int flag=; for (int i=len;i>;i--)
{
ans+=dp[i-][]*a[i];
if (flag) //前面有49就所有情况都是49数了
ans+=dp[i-][]*a[i];
if (!flag&&a[i]>) //加上4 9... 的情况
ans+=dp[i-][];
if (a[i]==&&a[i+]==)//判断是不是 49
flag=;
}
return ans;
} int main()
{
int t;
__int64 n;
Init();
scanf("%d",&t);
while (t--)
{
scanf("%I64d",&n);
printf("%I64d\n",solve(n+));//因为函数功能是 (0,n) 区间的49数,题目要求的是[1,n],所以+1
}
return ;
}
O-Bomb(数位dp)的更多相关文章
- hdu---(3555)Bomb(数位dp(入门))
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submi ...
- HDU 3555 Bomb 数位dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Mem ...
- HDU3555 Bomb —— 数位DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) M ...
- hud 3555 Bomb 数位dp
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Subm ...
- Hdu Bomb(数位DP)
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submiss ...
- hdu3555 Bomb(数位dp)
题目传送门 Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total ...
- HDU 3555 Bomb 数位DP 入门
给出n,问所有[0,n]区间内的数中,不含有49的数的个数 数位dp,记忆化搜索 dfs(int pos,bool pre,bool flag,bool e) pos:当前要枚举的位置 pre:当前要 ...
- hdu3555 Bomb 数位DP入门
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 简单的数位DP入门题目 思路和hdu2089基本一样 直接贴代码了,代码里有详细的注释 代码: ...
- Bomb 数位dp
---恢复内容开始--- 不能有49 数位dp模板题: #include<bits/stdc++.h> using namespace std; //input by bxd #defin ...
- 【hdu3555】Bomb 数位dp
题目描述 求 1~N 内包含数位串 “49” 的数的个数. 输入 The first line of input consists of an integer T (1 <= T <= 1 ...
随机推荐
- 关于宏:container_of和 offsetof以及list_for_each_entry
1.offsetof(TYPE, MEMBER) #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) offse ...
- C#程序不包含适合于入口点的静态“Main”方法怎么办
如下图所示,一般程序上次运行还好好的,而且不管你复制粘贴再简单的程序也出现这种错误提示. 先点击右侧的显示所有文件,下面列举了所有CS文件,右击点击包括在项目中,则该文件呈现绿色,再运行即可.不过 ...
- Win7梦幻桌面字体有问题怎么办
1:首先,下载我提供的压缩文件,解压"Win7中文界面梦幻桌面补丁",得到若干文件,这时可能需要管理员权限,详细的压缩包里有说明. 2: 然后在桌面上单击右键,可以发 ...
- Python 实现指定目录下 删除指定大小的文件
import os, sys from stat import * BIG_FILE_THRESHOLD = 6000L #1000000L dict1 = {} # dict2 = {} # def ...
- windows新建或者重命名文件及目录必须手动刷新才干显示出来问题解决方法
首先推断注冊表中HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Update\UpdateMode值是否为0,该值若为1表示手工刷新, 该 ...
- SDUT 2766-小明传奇2(母函数)
小明传奇2 nid=24#time" title="C.C++.go.haskell.lua.pascal Time Limit1000ms Memory Limit 65536K ...
- Kafka备忘
官网 http://kafka.apache.org/ 多生产者多消费者 多topic和多分区 多消费者组.每组中消息不能重复消费,组间不影响 启动 RunKafka(){ cd $kafka_hom ...
- SQL Server 中树形表数据的处理总结
-- 使用函数的方法: --建立 演示环境 if object_id('tb_bookInfo') is not null drop table tb_bookInfo go ),type int) ...
- sql语句偶记录
查看表结构: show FULL COLUMNS FROM tablename;
- Hibernate二次学习一----------搭建Hibernate
目录 1. 项目结构 1.2 hibernate.cfg.xml 1.3 entity 1.4 entity.hbm.xml 2. 测试 3. 总结 © 版权声明:本文为博主原创文章,转载请注明出处 ...