Bomb

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 13181    Accepted Submission(s): 4725

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
 
求1~n中有多少个数中没有49连续子序列的。
思路:
比较简单的数位dp。dp[len][w][is4]表示第len位的时候,之前是否存在49,并且之前的数字是否为4.
dp[len][w][is4] = sum(dp[len-1][fw][fis4]);
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define INF 1000000001
#define MOD 1000000007
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define pi acos(-1.0)
using namespace std;
const int MAXN = ;
ll dp[MAXN][][];
int digit[MAXN];
char s[MAXN];
ll dfs(int len,int w,int ismax,int pa,int is4)
{
if(len == )return w ? : ;
if(!ismax && dp[len][w][is4])return dp[len][w][is4];
int maxv = ismax ? digit[len] : ;
ll ans = ;
for(int i = ; i <= maxv; i++){
if(pa == && i == ){
ans += dfs(len-,,ismax && i == maxv,i,i == );
}
else {
ans += dfs(len-,w,ismax && i == maxv,i,i == );
}
}
if(!ismax)dp[len][w][is4] = ans;
return ans;
}
void solve()
{
int slen = strlen(s);
int len = ;
for(int i = slen - ; i >= ; i--){
digit[++len] = s[i] - '';
}
memset(dp,,sizeof(dp));
printf("%lld\n",dfs(len,,,-,));
}
int main()
{
int t;
scanf("%d",&t);
while(t--){
scanf("%s",s);
solve();
}
return ;
}

Bomb

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 13181    Accepted Submission(s): 4725

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
 
求1~n中有多少个数中没有49连续子序列的。
思路:
比较简单的数位dp。dp[len][w][is4]表示第len位的时候,之前是否存在49,并且之前的数字是否为4.
dp[len][w][is4] = sum(dp[len-1][fw][fis4]);

hdu3555 数位dp的更多相关文章

  1. hdu3555数位dp基础

    /* dp[i][0|1|2]:没有49的个数|最高位是9,没有49的个数|有49的个数 dp[i][0]=10*dp[i-1][0]-dp[i-1][1] dp[i][1]=dp[i-1][0] d ...

  2. hdu3555(数位DP dfs/递推)

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submi ...

  3. 数位dp浅谈(hdu3555)

    数位dp简介: 数位dp常用于求区间内某些特殊(常关于数字各个数位上的值)数字(比如要求数字含62,49): 常用解法: 数位dp常用记忆化搜索或递推来实现: 由于记忆化搜索比较好写再加上博主比较蒟, ...

  4. hdu3555 Bomb (记忆化搜索 数位DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  5. hdu---(3555)Bomb(数位dp(入门))

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submi ...

  6. hdu3555 Bomb 数位DP入门

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 简单的数位DP入门题目 思路和hdu2089基本一样 直接贴代码了,代码里有详细的注释 代码: ...

  7. 【Hdu3555】 Bomb(数位DP)

    Description 题意就是找0到N有多少个数中含有49. \(1\leq N \leq2^{63}-1\) Solution 数位DP,与hdu3652类似 \(F[i][state]\)表示位 ...

  8. 【hdu3555】Bomb 数位dp

    题目描述 求 1~N 内包含数位串 “49” 的数的个数. 输入 The first line of input consists of an integer T (1 <= T <= 1 ...

  9. [Hdu3555] Bomb(数位DP)

    Description 题意就是找0到N有多少个数中含有49. \(1\leq N \leq2^{63}-1\) Solution 数位DP,与hdu3652类似 \(F[i][state]\)表示位 ...

随机推荐

  1. HDU3535AreYouBusy[混合背包 分组背包]

    AreYouBusy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. Codeforces 687B. Remainders Game[剩余]

    B. Remainders Game time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  3. sql索引的填充因子多少最好,填充因子的作用?

    当创建一个新索引,或重建一个存在的索引时,你可以指定一个填充因子,它是在索引创建时索引里的数据页被填充的数量.填充因子设置为100意味着每个索引页100%填满,50%意味着每个索引页50%填满. 如果 ...

  4. Seajs是什么及sea.js 由来,特点以及优势

    Seajs是什么及sea.js 由来,特点以及优势 这篇文章主要介绍了Seajs的相关知识和和学习心得,适合刚接触SeaJS的同学,需要的朋友可以参考下,有更好的新手教程或文档,欢迎推荐.分享   1 ...

  5. jmeter 与 json

    1.添加一个 http信息头管理: Add new value for Name = “Content-Type” and value = “application/json” (without qu ...

  6. Mysql慢查询操作梳理

    Mysql慢查询解释MySQL的慢查询日志是MySQL提供的一种日志记录,它用来记录在MySQL中响应时间超过阀值的语句,具体指运行时间超过long_query_time值的SQL,则会被记录到慢查询 ...

  7. django复习笔记1:环境配置

    一.IDE 推荐使用sublime安装djaneiro插件. 1.安装方式 package control中搜索djaneiro 支持补全请参考:Django support for Sublime ...

  8. Linux 网络编程详解一(IP套接字结构体、网络字节序,地址转换函数)

    IPv4套接字地址结构 struct sockaddr_in { uint8_t sinlen;(4个字节) sa_family_t sin_family;(4个字节) in_port_t sin_p ...

  9. C# 如何定义让PropertyGrid控件显示[...]按钮,并且点击后以下拉框形式显示自定义控件编辑属性值

    关于PropertyGrid控件的详细用法请参考文献: 1.C# PropertyGrid控件应用心得 2.C#自定义PropertyGrid属性 首先定义一个要在下拉框显示的控件: using Sy ...

  10. 分布式消息系统:Kafka

    Kafka是分布式发布-订阅消息系统.它最初由LinkedIn公司开发,之后成为Apache项目的一部分.Kafka是一个分布式的,可划分的,冗余备份的持久性的日志服务.它主要用于处理活跃的流式数据. ...