Bomb(要49)--数位dp
Bomb
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 25866 Accepted Submission(s): 9810
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.
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<iostream>
#include<string.h>
#define ll long long
using namespace std;
ll shu[], dp[][];
ll dfs(ll len, bool if4, bool shangxian)
{
if (len == )
return ;
if (!shangxian&&dp[len][if4])
return dp[len][if4];
ll mx, cnt = ;//cnt记录的是区间内不含49的个数
mx = (shangxian ? shu[len] : );
for (ll i = ; i <= mx; i++)
{
if (if4&&i == )//如果shu[len]==4&&上一个状态是9
continue;
cnt = cnt + dfs(len - , i == , shangxian&&i == mx);
}
return shangxian ? cnt : dp[len][if4] = cnt;
}
ll solve(ll n)
{
memset(shu, ,sizeof(shu));
ll k = ;
while (n)//将n的每一位拆解出来逆序存在shu[i]中。eg:109,shu[0]=9,shu[1]=0,shu[2]=1;
{
shu[++k] = n % ;//注意这里是++k
n = n / ;
}
return dfs(k, false, true);
}
int main()
{
ll t;
scanf("%lld", &t);
while (t--)
{
ll n;
scanf("%lld", &n);//这里计算的区间是[0,n],题目要计算的是[1,n];
printf("%lld\n", n-(solve(n)-));
//如果是计算区间[a,b];printf(solve(b)-solve(a-1)); }
return ; }
Bomb(要49)--数位dp的更多相关文章
- hdu 3555 Bomb 炸弹(数位DP,入门)
题意: 给一个数字n,求从1~n中有多少个数是含有49的,比如49,149,1490等都是含49的. 思路: 2^64也顶多是十进制的20多位,那么按十进制位来分析更简单.如果能计算k位十进制数中分别 ...
- Bomb HDU - 3555 数位dp
Code: #include<cstdio> #include<algorithm> #include<cstring> #include<string> ...
- Bomb 数位dp
---恢复内容开始--- 不能有49 数位dp模板题: #include<bits/stdc++.h> using namespace std; //input by bxd #defin ...
- 数位dp介绍
不了解dp的可以先看一下dp 数位dp含义: 数位:一个数有个位,十位,百位,千位等等,数的每一位都是数位. 数位dp归为计数dp,是在数位上进行操作的dp. 数位dp的实质是一种快速枚举的方式,它满 ...
- hdu3555 Bomb (记忆化搜索 数位DP)
http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Memory ...
- 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 ...
- HDU 3555 Bomb(数位DP)
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Subm ...
- Bomb HDU - 3555 (数位DP)
Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terro ...
随机推荐
- Executing a Finite-Length Task in the Background
[Executing a Finite-Length Task in the Background] Apps that are transitioning to the background can ...
- 手机端获取用户详细地理位置(高德地图API)
项目开发需要获取用户详细的地理位置信息,使用了高德地图API接口 1,注册高德地图开发者账号获取开发者Key 2,页面调用 <script type="text/javascript& ...
- raw格式转换成qcow2格式
qemu-img convert -f raw redhat6.7-kvm-postgresql9.2.3-8disk-pulsar2.2 -O qcow2 redhat6.7-kvm-postgre ...
- Kubernetes 中的pv和pvc
原文地址:http://www.cnblogs.com/leidaxia/p/6485646.html 持久卷 PersistentVolumes 本文描述了 Kubernetes 中的 Persis ...
- UVa 10570 Meeting with Aliens (暴力)
题意:给定一个排列,每次可交换两个数,用最少的次数把它变成一个1~n的环状排列. 析:暴力题.很容易想到,把所有的情况都算一下,然后再选出次数最少的那一个,也就是说,我们把所有的可能的形成环状排列全算 ...
- Spring3.x错误----java.lang.ClassNotFoundException:org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException
Spring3.x错误: 解决方法: 缺少aspectjweaver.jar包 下载地址: https://cn.jarfire.org/aspectjweaver.html
- Hello_Depth_Perception 任务二:Project Tango采集深度感知数据
Java API Depth Perception Tutorial深度感知教程 Configuration 配置信息 In order to use depth perception, your T ...
- (深搜)Oil Deposits -- hdu -- 1241
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1241 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- Python WebDriver + Firefox 文件下载
firefox可以通过 在地址栏输入:about:config 或about:aupport 来查看或修改配置信息. 这里有两种解决方式, 1.设置自动保存下载 如下图勾选:以后自动采用相同的动作处理 ...
- 使用JDK实现动态代理