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 ...
随机推荐
- 【KMP】Censoring
[KMP]Censoring 题目描述 Farmer John has purchased a subscription to Good Hooveskeeping magazine for his ...
- memcached基本操作指令
item执行命令: 第一行:Key Flags ExpirationTime BytesKey:Key 用于查找缓存值Flags:一个32位的标志值,客户机使用它存储关于键值对的额外信息Expirat ...
- 数据库优化SQL
sql优化规则: 1.对于查询,尽量不要使用全表扫描,尽量在where子句以及order by所对应的字段建立索引. 2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放 ...
- centos7 + postgresql10
mysql被黑惨了,换了个超复杂的密码都不行,黑客会删除你所有的自定义库,然后插一个warning表,让你给他汇比特币. 提醒大家放在在公网的DB,要非常注意数据的安全性,万一被勒索了,真是mmp了. ...
- 如何演讲-摘录自TED
一.首先,只传递一个主要思想 想法是个很复杂的东西,你要对你的内容做减法,突出重点,只关注一个主要思想,也就是你最富有热情的观点,利用机会好好的阐述它.你要给出案例,分享案例,生动阐述所以,找到一个 ...
- Makefile中 -I -L -l区别
我们用gcc编译程序时,可能会用到"-I"(大写i),"-L"(大写l),"-l"(小写l)等参数,下面做个记录: 例: gcc -o he ...
- 安卓开发之ArrayAdapter使用
package com.lidaochen.test; import android.support.v7.app.AppCompatActivity; import android.os.Bundl ...
- 流媒体服务器搭建 ffmpeg + nginx
第一部分: mkdir ~/working 切换到~/working目录下 cd ~/working 获取nginx源码: wget http://nginx.org/download/nginx-1 ...
- python 删除特定字符所在行
#查询文件中含有特殊字符串的行 #!/usr/bin/python # -*- coding:utf- -*- import re file1 = open('test.txt','r+') istx ...
- mock.js学习之路(二)easy-mock(Vue中使用)
1.easy-mock建立外部数据,注册账号,创建数据,详细使用过程参照https://www.easy-mock.com/docs文档说明 2.项目中如何引入使用 ①配置一下config.index ...