【数位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了.那时候完全不知数 ...
随机推荐
- php utf8 gbk 数组 互转
这些都是工作中常用的 前几年写过 但没有记录的习惯,后边有要用到麻烦,现在记录下 以后直接拿来用 数组里的 utf8_to_gbk 方法 是上一篇写的 直接调用 public static funct ...
- 综合练习2 设置访问权限,Easy-IP访问外网,内外网访问
实验拓扑图: 实验要求: 1.pc.路由.交换基本配置,vlan间路由互通. 2.vlan20.vlan30可以访问FTP,VLAN10不允许访问FTP. 3.AR1通过easy-ip方式实现私网地址 ...
- nginx之配置proxy_set_header问题梳理
客户端请求web服务,客户端:ip:192.168.223.1 nginx作为反向代理服务器:192.168.223.136 nginx作为后端web服务器:192.168.223.137 前提条件: ...
- C#学习笔记06--类/对象/访问修饰符/方法
编程思想 1.面向过程 面向过程是要把问题解决的过程分成有一定顺序的不同步骤, 然后按照步骤一步步的将问题解决. 2.面向对象 面向对象解决问题的思路是先分析问题中所涉及的对象, 然后 ...
- LC 173. Binary Search Tree Iterator
题目描述 Implement an iterator over a binary search tree (BST). Your iterator will be initialized with t ...
- time() 函数时间不同步问题
1.时区设置问题 处理方法:编辑php.ini 搜索 “timezone” 改写为 PRC 时区 2.服务器时间不同步 处理方法:设置服务器时间和本地时间进行同步
- Flask 中command的使用
其实这个标题有点大了,只是记录以一下flask中command的一个使用方式,具体用法还需要看相关文档. 之前的项目中需要加一个定时任务所以在flask中写了个任务执行. 首先需要在manage.py ...
- maven 依赖 无法下载到jar包,典型的json-lib包
<dependency> <groupId>net.sf.json-lib</groupId> <artifact ...
- 【百度之星2019】Strassen
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6719 在本题中,我们只有两种方法计算两个的矩阵的乘积,第一种为定义法,需要次乘法和次加法.第二种为 ...
- shell习题第25题:判断是否开启web服务
[题目要求] 写一个脚本判断我的linux服务器是否开启web服务?监听80端口 [核心要点] netstat -lntp | grep '80' [脚本] #!/bin/bash n=`netsta ...