hdu 3555 Bomb 【数位DP】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555
题意:上一题是不要62 这个是“不要49”
代码:
#include <stdio.h>
#include <ctime>
#include <math.h>
#include <limits.h>
#include <complex>
#include <string>
#include <functional>
#include <iterator>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <bitset>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <iostream>
#include <ctime>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <time.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
using namespace std;
#define N 50
using namespace std;
int bit[N];
long long dp[N][3];
/*
dp[i][0]:前i位不含 49 的个数。
dp[i][1]:前i位不含 49 数且i+1位是4的个数。
dp[i][2]:前i位含 49 的个数。
*/
long long dfs(int pos, int st, bool flag)
{
if (pos == 0) return st == 2;
if (flag && dp[pos][st] != -1) return dp[pos][st];
long long ans = 0;
int u = flag ?
9 : bit[pos];
for (int d = 0;d <= u;d++)
{
if (st == 2 || (st == 1 && d == 9))
ans += dfs(pos - 1, 2, flag || d<u);
else if (d == 4)
ans += dfs(pos - 1, 1, flag || d<u);
else
ans += dfs(pos - 1, 0, flag || d<u);
}
if (flag) dp[pos][st] = ans;
return ans;
}
long long solve(long long n)
{
int len = 0;
while (n)
{
bit[++len] = n % 10;
n /= 10;
}
return dfs(len, 0, 0);
}
int main()
{
long long n;
int t;
scanf("%d",&t);
while (t--)
{
scanf("%lld", &n);
memset(dp, -1, sizeof(dp));
printf("%lld\n", solve(n));
}
return 0;
}
hdu 3555 Bomb 【数位DP】的更多相关文章
- HDU 3555 Bomb 数位dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Mem ...
- HDU 3555 Bomb 数位DP 入门
给出n,问所有[0,n]区间内的数中,不含有49的数的个数 数位dp,记忆化搜索 dfs(int pos,bool pre,bool flag,bool e) pos:当前要枚举的位置 pre:当前要 ...
- HDU - 3555 - Bomb(数位DP)
链接: https://vjudge.net/problem/HDU-3555 题意: The counter-terrorists found a time bomb in the dust. Bu ...
- Bomb HDU - 3555 (数位DP)
Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terro ...
- HDU(3555),数位DP
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others ...
- HDU 3555 Bomb (数位DP-记忆化搜索模板)
题意 求区间[1,n]内含有相邻49的数. 思路 比较简单的按位DP思路.这是第一次学习记忆化搜索式的数位DP,确实比递推形式的更好理解呐,而且也更通用~可以一般化: [数位DP模板总结] int d ...
- hud 3555 Bomb 数位dp
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Subm ...
- hdoj 3555 BOMB(数位dp)
//hdoj 3555 //2013-06-27-16.53 #include <stdio.h> #include <string.h> __int64 dp[21][3], ...
- 数位DP入门之hdu 3555 Bomb
hdu 3555 Bomb 题意: 在1~N(1<=N<=2^63-1)范围内找出含有 ‘49’的数的个数: 与hdu 2089 不要62的区别:2089是找不不含 '4'和 '62'的区 ...
- HDU 3555 Bomb(数位DP模板啊两种形式)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 Problem Description The counter-terrorists found ...
随机推荐
- Jquery 全选、反选问题的记录
<div id="list"> <ul id="choseList" > <li><input type=" ...
- myeclipse中js文件报错
这几天在myeclipse中添加文件时,会报错,但是代码是从官网上下载的,没有错误,只是myeclipse的检查较为严格.在网上找到解决方案,希望可以帮到强迫症的人. 解决步骤: 1.window→P ...
- [算法天天练] - C语言实现约瑟夫环(2)
Linux下 #include <stdlib.h>#include <stdio.h> int main(){ int n,m,i,s = 0; printf("E ...
- C/C++ struct定义、声明、对齐方式
一.定义/声明方式 第一种:仅有结构体名,不定义/声明变量 struct MyStruct { int i: char a[10]; double b; }:第二种:有结构体名,并声 ...
- blender--(凹凸贴图)................https://jingyan.baidu.com/article/9f63fb917c4becc8400f0ea8.html
在blender中直接绘制模型凹凸纹理细节 听语音 | 浏览:32 | 更新:2018-02-20 11:18 1 2 3 4 5 6 7 分步阅读 在blender中为了表现更多的模型细节,我们会常 ...
- 梦想CAD控件图层COM接口知识点
梦想CAD控件图层COM接口知识点 一.新建图层 主要用到函数说明: _DMxDrawX::AddLayer 增加新的图层.详细说明如下: 参数 说明 BSTR pszName 图层名 c#中实现代码 ...
- BZOJ1013 + BZOJ1923 + POJ1830 (高斯消元)
三个题放在一起写了 主要是搞搞模板 在这里简述一下怎么写高斯消元 就和代数里学的加减消元学的一样 把矩阵化为上三角形形式 然后进行回代 同时枚举当前要消元的未知数和当前化简到哪一行了 然后从这一行往后 ...
- JSONP 应用
受限于浏览器的同源安全策略, js 无法发起跨域的请求. 但是 HTML 中的 <script> 标签却可以引入跨域的文件使用. 而 JSONP 就是利用 <script> 的 ...
- (转)MySQL中的索引详讲
序言 之前写到MySQL对表的增删改查(查询最为重要)后,就感觉MySQL就差不多学完了,没有想继续学下去的心态了,原因可能是由于别人的影响,觉得对于MySQL来说,知道了一些复杂的查询,就够了,但是 ...
- 【LeetCode】9、Palindrome Number(回文数)
题目等级:Easy 题目描述: Determine whether an integer is a palindrome. An integer is a palindrome when it rea ...