hdu3555(数位dp入门题)
来源:互联网 发布:程序员 明基 不闪屏 编辑:程序博客网 时间:2024/05/01 21:13
Bomb
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 6762 Accepted Submission(s): 2351
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?
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.
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
3150500
Sample Output
0115HintFrom 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.
数位dp模板题
#include<set>#include<queue>#include<cmath>#include<cstdio>#include<vector>#include<string>#include<utility>#include<cstring>#include<iostream>#include<algorithm>#include<functional>#define Inf (1<<30)#define LL unsigned long long#define MOD 1000000009#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;LL dp[100][100];void init(){ dp[0][0]=1; for(int i=1;i<=64;i++)//dp[i][j]表示长度是i的以j开头的没有49的字串个数 { for(int j=0;j<=9;j++) { for(int k=0;k<=9;k++) if(!(k==9&&j==4))dp[i][j]+=dp[i-1][k]; } }}LL query(LL x){ LL a[70],L=0,ans=0; for(int i=1;x;i++) { a[i]=x%10; x/=10; L++; } a[L+1]=0; for(int i=L,j=0;i>=1;i--) { for(j=0;j<a[i];j++) { if(!(j==9&&a[i+1]==4))ans+=dp[i][j]; } if(a[i]==9&&a[i+1]==4)break; } return ans;}int main(){ int T; LL n; init(); //freopen("D:\\oo.txt","r",stdin); scanf("%d",&T); while(T--) { scanf("%I64u",&n); printf("%I64u\n",n+1-query(n+1));///查询0到n,[0,n]的没有49的个数 } return 0;}
0 0
- hdu3555(数位dp入门题)
- hdu3555 数位dp入门题
- hdu3555 数位dp 入门
- HDU3555 数位DP入门!
- hdu3555+cf55D 数位dp入门题
- 【HDU3555】Bomb-数位DP入门题
- HDU3555:Bomb(数位dp入门)
- hdu3555(数位dp)
- hdu3555(数位dp)
- hdu3555(数位dp)
- hdu3555 + 2089 (数位dp入门)
- HDU3555 常规数位dp入门....
- 【数位DP入门】HDU3555 Bomb
- HDU3555 Bomb(数位dp)
- HDU3555 Bomb(数位dp)
- HDU3555 Bomb (数位dp)
- hdu3555 Bomb(数位dp)
- HDU3555 Bomb(数位DP)
- 究竟如何威尔的Web Analytics帮助网络营销
- 利用CocoStudio导出pvr文件的碎图方式
- LeetCode Linked List Cycle II
- 工作流 工作流脚本返回值或者不返回值的使用
- HDOJ 1001 Sum Problem
- hdu3555(数位dp入门题)
- c++中重载输出操作符,为什么要返回引用
- 磁选工艺流程与设备介绍
- Android中通过广播方式调起第三方App
- 破碎机锤头的耐磨性研究
- 网络用户购买行为心理分析
- usb 驱动书籍
- uri url urn 的区别联系
- 图像颜色特征提取