【数位DP-板子题目】HDU-3555-Bomb- [只要49]
Bomb Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others)
Total Submission(s): Accepted Submission(s): Problem Description
The 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 to N. If the current number sequence includes the sub-sequence "", 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? Input
The first line of input consists of an integer T ( <= T <= ), indicating the number of test cases. For each test case, there will be an integer N ( <= N <= ^-) as the description. The input terminates by end of file marker. Output
For each test case, output an integer indicating the final points of the power. Sample Input Sample Output Hint
From to , the numbers that include the sub-sequence "" are "","","","","","","","","","","","","","","",
so the answer is .
题解:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <math.h>
#include <string.h>
#include<set>
using namespace std;
#define inf 0x3f3f3f3f
const double pi=acos(-1.0); ///数位DP,只要49
#define ll long long
#define lson root<<1
#define rson root<<1|1
const ll mod = ;
#define ull unsigned long long
ll digit[];
ll dp[][];
///limit表示是否受限,最初进行的时候必定受限!
ll Cul(int len,bool if4,bool limit){ if(len<)return ;
if(!limit&&dp[len][if4]!=-)return dp[len][if4];
int up_bound=(limit==)?digit[len]:;
ll ans=;
for(int i=;i<=up_bound;i++)
{
if(if4&&i==)
continue;
ans+=Cul(len-,i==,limit&&i==digit[len]);
}
dp[len][if4]=ans;
return ans;
} ll solve(ll n){
int k=;
while(n){
digit[++k]=n%;
n/=;
}
memset(dp,-,sizeof(dp));
return Cul(k,false,true);
} int main(){ ll n,T;
cin>>T;
while(T--){
scanf("%lld",&n);
printf("%lld\n",n-solve(n)+); } return ;
}
【数位DP-板子题目】HDU-3555-Bomb- [只要49]的更多相关文章
- 数位DP入门之hdu 3555 Bomb
hdu 3555 Bomb 题意: 在1~N(1<=N<=2^63-1)范围内找出含有 ‘49’的数的个数: 与hdu 2089 不要62的区别:2089是找不不含 '4'和 '62'的区 ...
- 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题
[HDU 3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...
- hdu 3555 Bomb(不要49,数位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模板啊两种形式)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 Problem Description The counter-terrorists found ...
- hdu 3555 Bomb 【数位DP】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 题意:上一题是不要62 这个是"不要49" 代码: #include < ...
- HDU 3555 Bomb(数位DP)
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Subm ...
- 数位dp整理 && 例题HDU - 2089 不要62 && 例题 HDU - 3555 Bomb
数位dp: 数位dp是一种计数用的dp,一般就是要统计一个区间[li,ri]内满足一些条件数的个数.所谓数位dp,字面意思就是在数位上进行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://blog.csdn.net/a1dark 分析:初学数位DP完全搞不懂.很多时候都是自己花大量时间去找规律.记得上次网络赛有道数位DP.硬是找规律给A了.那时候完全不知数 ...
随机推荐
- 【C/C++开发】关于位域操作
几篇较全面的位域相关的文章: http://www.uplook.cn/blog/9/93362/ C/C++位域(Bit-fields)之我见 C中的位域与大小端问题 内存对齐全攻略–涉及位域的内存 ...
- Spring + Atomikos 分布式事务实现方式
不同的数据库一定要分包建立 引用:http://blog.csdn.net/benluobobo/article/details/49818017 http://blog.csdn.net/yds49 ...
- iframe里访问父级里的方法属性
window.parent.attributeName; // 访问属性attributeName是在父级窗口的属性名 window.parent.Func(); // 访问属性Func()是在父 ...
- RISC-V汇编指南
原文出处:https://github.com/riscv/riscv-asm-manual/blob/master/riscv-asm.md RISC-V Assembly Programmer's ...
- postman带Token测试接口
首先打开postman.是这样的界面 我们的需求是这样的.实现登录之后返回token.然后请求其他接口时在header头中带上token信息. OK.接下来我们这样操作: 现在登录没有操作token. ...
- Oracle10G安装手册
环境准备: 操作系统:windows-7 32bit 数据库:oracle10G 网络环境:不能使用DHCP模式,必须设置一个固定IP地址. 运行安装 1.打开oracle安装文件,请勿直接选择set ...
- Win10 改为用 Ctrl+Shift 切换中英输入语言而不是 Win+空格
是切换中英输入语言,而不是切换输入法,如图: 步骤: 设置 > 设备 > 输入 > 高级键盘设置 > 语言栏选项 > 高级键盘设置 > 更改按键顺序 > 切换 ...
- Linux centos 7下搭建mosquitto
Centos7安装 1.网卡名改为enth0 A: vim /etc/sysconfig/grub B: 第三行添加"net.ifnames=0 biosdevname=0" ...
- 1192: 零起点学算法99——The sum problem(C)
一.题目 http://acm.wust.edu.cn/problem.php?id=1192&soj=0 二.分析 要求从序列1,2,3,,,N,中截取一部分使他们的和为M 输入多组数据 输 ...
- (十五)Activitivi5之多用户任务分配
一.概念 我们在开发的时候,有一种情况是这样的, 我们有一个任务,可以让多个用户中的任何一个人办理即可,比如某个审批任务, 张三,李四,王五他们中的任何一人办理下都行,这时候,我们用到多用户任务分配. ...