hdu3555(数位DP dfs/递推)
Bomb
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 10649    Accepted Submission(s): 3758
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?
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.
1
50
500
1
15
From 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.
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace std;
#define LL long long
LL dp[][];
int digit[]; LL dfs(int len,bool state,bool fp)
{
if(!len)
return ;
if(!fp && dp[len][state] != -)
return dp[len][state];
LL ret = ;int fpmax = fp ? digit[len] : ;
for(int i=;i<=fpmax;i++)
{
if(state && i == )
continue;
ret += dfs(len-,i == ,fp && i == fpmax);
//第二个参数表明这位是否为4,如果为4,下一位就不能为9,否则没有限制
//第三个参数表明前缀是否相同,如果相同,下一位就只能枚举到最大值,否则就没有限制
}
if(!fp)
dp[len][state] = ret;
return ret; //ret代表0到n不含49的个数
} LL f(LL n)
{
int len = ;
while(n)
{
digit[++len] = n % ;
n /= ;
}
return dfs(len,false,true);
} int main()
{
//freopen("test.txt","r",stdin);
LL a,b;
memset(dp,-,sizeof(dp));
int t;
scanf("%d",&t);
while(t--)
{
cin>>b;
cout<<(b+-f(b))<<endl;
} return ;
}
hdu3555(数位DP dfs/递推)的更多相关文章
- [AHOI2009]中国象棋    DP,递推,组合数
		
DP,递推,组合数 其实相当于就是一个递推推式子,然后要用到一点组合数的知识 一道很妙的题,因为不能互相攻击,所以任意行列不能有超过两个炮 首先令f[i][j][k]代表前i行,有j列为一个炮,有k列 ...
 - UVa 926【简单dp,递推】
		
UVa 926 题意:给定N*N的街道图和起始点,有些街道不能走,问从起点到终点有多少种走法. 很基础的dp.递推,但是有两个地方需要注意,在标记当前点某个方向不能走时,也要同时标记对应方向上的对应点 ...
 - hdu3555 数位dp
		
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Subm ...
 - HDU 5965 三维dp 或 递推
		
题意:= =中文题 思路一:比赛时队友想的...然后我赛后想了一下想了个2维dp,但是在转移的时候,貌似出了点小问题...吧?然后就按照队友的思路又写了一遍. 定义dp[i][j][k],表示第i列, ...
 - 【BZOJ4944】【NOI2017】泳池 概率DP 常系数线性递推 特征多项式 多项式取模
		
题目大意 有一个\(1001\times n\)的的网格,每个格子有\(q\)的概率是安全的,\(1-q\)的概率是危险的. 定义一个矩形是合法的当且仅当: 这个矩形中每个格子都是安全的 必须紧贴网格 ...
 - [NOI2017]泳池——概率DP+线性递推
		
[NOI2017]泳池 实在没有思路啊~~~ luogu题解 1.差分,转化成至多k的概率减去至多k-1的概率.这样就不用记录“有没有出现k”这个信息了 2.n是1e9,感觉要递推然后利用数列的加速技 ...
 - [hdu 2089] 不要62  数位dp|dfs  入门
		
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 题意:求[n, m]区间内不含4和62的数字个数. 这题有两种思路,直接数位dp和dfs 数位d ...
 - lightoj 1126 - Building Twin Towers(dp,递推)
		
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1126 题解:一道基础的dp就是简单的递推可以设dp[height_left][ ...
 - BZOJ5017 [Snoi2017]炸弹[线段树优化建边+scc缩点+DAG上DP/线性递推]
		
方法一: 朴素思路:果断建图,每次二分出一个区间然后要向这个区间每个点连有向边,然后一个环的话是可以互相引爆的,缩点之后就是一个DAG,求每个点出发有多少可达点. 然后注意两个问题: 上述建边显然$n ...
 
随机推荐
- HDU 5245
			
题目大意: 每次随机选择两个点,便把这两个点之间形成的子矩阵上的每一个方块涂色,问随机选择k次,整个m*n的矩阵中有多少个小方块被涂上了颜色 这道题不难,但自己智商实在捉急,一直想不出来... 因为这 ...
 - E题
			
题目大意: 找到一个最小的l值,使得a到b-l+1中任取一个数开始前进l次,中间包含至少有k个素数,如果找不到,返回-1: 运用素数打表法和2分法便能简单搞定: 题目链接:http://codefor ...
 - CF778A:String Game
			
给出字符串s和t,以及s的长度n的一个全排列,求按照这个排列依次删除s的字符,删到何时s中不含子序列t. 解法一: t中的每个字符的位置在s中跳啊跳,合法的情况下t中的字符在s中的位置应该是单调递增的 ...
 - 用DW制作简单的浮动广告
			
原文发布时间为:2008-11-08 -- 来源于本人的百度文章 [由搬家工具导入] 浮动广告可以用层和时间轴结合做出,先选择你的dreamweaver“窗口”,然后从“窗口”菜单中选择“时间轴”,时 ...
 - linux date 格式化时间和日期
			
[root@108test ~]# date -d today +"%Y-%m-%d" 2008-05-07 [root@108test ~]# date -d today + ...
 - Sudoku Killer--hdu1426(数独  跟上一题差不多  但是输入时问题)
			
http://acm.hdu.edu.cn/showproblem.php?pid=1426 注意输入问题就行 还是dfs #include<stdio.h> #include<st ...
 - Construct Binary Tree from Preorder and Inorder Traversal (DFS,参考)
			
Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...
 - MySQL事务及Spring事务管理
			
事务,是在数据库中用于保证数据正确性的一种机制,涉及到很多概念以及不同的情况,这里做一个总结 相关概念 事务四特性(ACID) 原子性(Atomicity,或称不可分割性):要么全部完成或者全部不完成 ...
 - 石家庄地铁查询PSP0级
			
一.需求 :地铁(石家庄地铁)线路查询 二. 学生:洪鼎淇 合作对象:宋子健 时间记录日志: 日期 开始时间 结束时间 中断时间 净时间 活动 2019/3/30 10:00 14:0 ...
 - CSS3 水波纹
			
css3 动画设置水波纹,效果如下图: 源码: <!DOCTYPE html> <html lang="en"> <head> <meta ...