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. 05章项目: QuickHit快速击键

    一.项目分析 根据输入速率和正确率将玩家分为不同等级,级别越高,一次显示的字符数越多,玩家正确输入一次的得分也越高.如果玩家在规定时间内完成规定次数的输入,正确率达到规定要求,则玩家升级.玩家最高级别 ...

  2. 2016.11.17 NOI plus day0

    今天很乱乱乱乱 根本不想写代码 玩了一早上了 昨晚失眠了 今天又懵逼了 中午就要走了 明天就要考试了 考完试回来就要补文化课了 现在我的内心很平静 因为已经紧张的冻结了 你知道什么叫彷徨么? 机房里的 ...

  3. .NET(C#) File类的常用方法

    MSDN的File类 File类在MSDN:https://msdn.microsoft.com/zh-cn/library/system.io.file_methods(v=vs.110).aspx ...

  4. GIT安装和使用

    GIT 首先登陆github账号   在本地创建一个文件夹   点击文件夹,右键,选择Git create repository here 操作之后,会生成一个.git文件(这个文件为隐藏文件) 在此 ...

  5. windows下 git配置ssh

    1. 打开 git bash 2. cd ~/.ssh 3. ssh-genkey (一致next),  会生成 id_rsa (密钥); id_rsa.pub(公钥) 4. 用记事本打开 id_rs ...

  6. 实例讲解表单验证插件Validation的应用

    jquery.Validation是一款优秀的jquery插件,它能对客户端表单进行验证,并且提供了许多可以定制的属性和方法,良好的扩展性.现在 结合实际情况,我把项目中经常要用到的验证整理成一个实例 ...

  7. Orchard CRM 更新 - 同时支持 Microsoft Dynamics CRM 2011, 2013, 2015, 2016!

    本版本支持: 使用Orchard 1.8.1 系统 Dynamics CRM 2015 DLL .Net Framework 4.5.2 演示版本: http://www.orchardcrm.com ...

  8. mssql 2008 复制订阅

    广域网的复制订阅 准备工作: 1.a.b服务器创建相同的系统用户密码 2.在a服务器 sql server 配置管理器 创建别名 ip填写b服务器的ip, b服务器端口号 3.在b服务器  sql s ...

  9. Stream 和 byte[]

    C# Stream 和 byte[] 之间的转换   一. 二进制转换成图片MemoryStream ms = new MemoryStream(bytes);ms.Position = 0;Imag ...

  10. 丰富Easyui 的插件 - lookup

    插件用途: 主要用于表单中,某字段的内容是用其他表里的记录ID.当然你可以使用combobox.combotree.combogrid等,但有时这些表现方式并不是很好,希望弹出个层,然后在去做一些查询 ...