Hdu Bomb(数位DP)
Bomb
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 16713 Accepted Submission(s): 6128
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 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?
Input
The 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.
Output
For each test case, output an integer indicating the final points of the power.
Sample Input
3
1
50
500
Sample Output
0
1
15
HintFrom 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.
Author
fatboy_cw@WHU
Source
2010 ACM-ICPC Multi-University Training Contest(12)——Host by WHU
/*
数位DP.
f[i][j]表示以j开头的i位数的决策.
倒序存储
最后还要加一位统一开区间处理.
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#define MAXN 25
#define LL long long
using namespace std;
LL f[MAXN][MAXN],ans,n;
int t,l,a[MAXN];
void pre()
{
f[0][0]=1;
for(int i=1;i<=20;i++)//枚举位数.
for(int j=0;j<=9;j++)//枚举这一位数.
for(int k=0;k<=9;k++)//枚举上一位数.
{
if(j==4&&k==9) continue;
f[i][j]+=f[i-1][k];
}
return ;
}
void slove()
{
n++;ans=n;
l=0;memset(a,0,sizeof a);
while(n) a[++l]=n%10,n/=10;
a[l+1]=0;
for(int i=l;i;i--)
{
for(int j=0;j<a[i];j++)
{
if(a[i+1]==4&&j==9) continue;
ans-=f[i][j];
}
if(a[i]==9&&a[i+1]==4) break;
}
cout<<ans<<endl;
return ;
}
int main()
{
pre();scanf("%d",&t);
while(t--) cin>>n,slove();
return 0;
}
Hdu Bomb(数位DP)的更多相关文章
- hdu 4507 数位dp(求和,求平方和)
http://acm.hdu.edu.cn/showproblem.php?pid=4507 Problem Description 单身! 依旧单身! 吉哥依旧单身! DS级码农吉哥依旧单身! 所以 ...
- hdu 4352 数位dp + 状态压缩
XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 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:当前要 ...
- HDU3555 Bomb —— 数位DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) M ...
- hdu---(3555)Bomb(数位dp(入门))
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submi ...
- hdu3555 Bomb 数位DP入门
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 简单的数位DP入门题目 思路和hdu2089基本一样 直接贴代码了,代码里有详细的注释 代码: ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6156 数位DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6156 题意:如题. 解法:数位DP,暴力枚举进制之后,就转化成了求L,R区间的回文数的个数,这个直接做 ...
- hud 3555 Bomb 数位dp
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Subm ...
随机推荐
- GCD&&素筛&&快速幂 --A - Pseudoprime numbers
Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a (mod p). Th ...
- Python取整数
1.向下取整: int()>>> a = 14.38>>> int(a)14 2.向上取整:ceil()使用ceil()方法时需要导入math模块,例如>&g ...
- 选择最佳策略:简单的方式和globals()
promos = [fidelity_promo, bulk_item_promo, large_order_promo] ➊ def best_promo(order): ➋ "" ...
- CSS实现单选按钮
import React from 'react' import PropTypes from 'prop-types' import CX from 'classnames' import _ fr ...
- 社工工具包 SEToolkit
社会工程学(Social Engineering)简称社工,其通过分析攻击对象的心理弱点,利用人性的本能反应,以及任何好奇心,贪婪等心理特征进行的,使用诸如假冒,欺骗,引诱等多种手段来达成攻击目标的一 ...
- VS显示方法引用
菜单栏 工具->选项->文本编辑器->所有语言->CodeLens 勾上即可
- JDK,JRE,JVM 关系和概念
JDK : Java Development ToolKit(Java开发工具包).JDK是整个JAVA的核心,包括了Java运行环境(Java Runtime Envirnment),一堆Java工 ...
- VirtualBox使用
热键:Right Ctrl 串口 端口编号: COM1 -> /dev/ttyS0 COM2 -> /dev/ttyS1 COM3 -> /dev/ttyS2 COM4 -> ...
- 15.SpringMVC核心技术-数据验证
在 Web 应用程序中,为了防止客户端传来的数据引发程序的异常,常常需要对数据进行验证. 输入验证分为客户端验证与服务器端验证.客户端验证主要通过 JavaScript 脚本进 行, 而服务器端验证则 ...
- linux终端c语言改变输出字体颜色
Linux下C改变输出字体颜色 例: #include int main() { printf("\033[31mThis is RED.\n\033[0m"); return 0 ...