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. SQL2012连接字符串

    安装了sqlserver2012数据库,测试一包代码,搜索网上的方法,死活连接不上,最后偶然测试通过,居然是连接字符串的问题. “如果开发软件的时候是在局域网或者是在本机,并且数据库不在远程计算机上面 ...

  2. 初识hibernate框架之一:进行简单的增删改查操作

    Hibernate的优势 l 优秀的Java 持久化层解决方案  (DAO) l 主流的对象—关系映射工具产品 l 简化了JDBC 繁琐的编码 l 将数据库的连接信息都存放在配置文件 l 自己的ORM ...

  3. 那些强悍的PHP一句话后门

    强悍的PHP一句话后门这类后门让网站.服务器管理员很是头疼,经常要换着方法进行各种检测,而很多新出现的编写技术,用普通的检测方法是没法发现并处理的.今天我们细数一些有意思的PHP一句话木马.利用404 ...

  4. samsung Galaxy s2(GT i9100g )刷机升级至4.4小记

    从昨天上午到现在,大部分时间都是在将i9100g更新到4.4.虽然中途也做了一些别的事情,但是更新过程还是走了一点弯路,比开始预想的稍微慢了一点,现在将完整的更新步骤分享给大家,以帮助后来的同学.升级 ...

  5. jquery插件集

    自定义滚动条jquery-custom-scrollbar 放大镜 fancybox,lightbox,jquery zoom

  6. C#实现php的hash_hmac函数

    from:http://blog.csdn.net/ciaos/article/details/12618487 PHP代码示例如下 <?php         $res1 = hash_hma ...

  7. workqueue机制分析之wb_workfn函数

    上面一篇文章说到: process_one_work中最重要的一件事情就是worker->current_func(work); 这里就具体到一项很具体的任务了,由于我要研究文件系统嘛,所以很自 ...

  8. 带OUTPUT参数的CLR存储过程

    前面写了一篇<带参数的CLR存储过程>http://www.cnblogs.com/insus/p/4373605.html ,如果我们需要创建一个带OUTPUT返回值. 实现它,可以先了 ...

  9. C# 多重overide

    overide 是覆盖的意思,用在且仅用在虚函数上,虚函数可以是virtual或abstract修饰的,或者是overide修饰的. 文档大概是这么说的. 由此知道,由overide修饰的函数都是虚函 ...

  10. Session一次错误记录

    /// <summary>        /// 验证登录状态是否已失效        /// </summary>        /// <returns>< ...