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 ...
随机推荐
- HTML城市联动
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- taskctl命令行类(sh、exe、python新增scp)插件升级扩展
转载自: http://www.taskctl.com/forum/detail_129.html 上次写了一个帖子 TASKCTL中不使用代理,通过ssh免密连接执行远程脚本配置(SSH插件扩展)h ...
- swift VS NSObject
Any class that does not inherit from another class is known as a base class. Swift classes do not in ...
- Python的伪造数据库:Faker
faker 是一个可以让你生成伪造数据的Python包,在软件需求.开发.测试过程中常常需要利用一些假数据来做测试,这种时候就可以使用 Faker 来伪造数据从而用来测试. 一.Faker安装 pip ...
- C++算法库学习__std::sort__对 vector进行排序_排序后就可以进行使用std::lower_bound进行二分查找(查找第一个大于等于指定值的迭代器的位置)__std::unique
std::sort 对vector成员进行排序; std::sort(v.begin(),v.end(),compare); std::lower_bound 在排序的vector中进行 ...
- Vue渲染原理
现在基本所有的框架都已经认同这个看法——DOM应尽可能是一个函数式到状态的映射.状态即是唯一的真相,而DOM状态只是数据状态的一个映射.如下图所示,所有的逻辑尽可能在状态的层面去进行,当状态改变的时候 ...
- JavaScipt30(第二个案例)
承接上篇https://www.cnblogs.com/wangxi01/p/10641115.html,这是第二个案例 附上项目链接: https://github.com/wesbos/JavaS ...
- wpf 自定义单选按钮 RadioButton
新建RadioButtonEx.cs public class RadioButtonEx : RadioButton { public Geometry SelectIcon { get { ret ...
- 学习笔记7——使用Scanner获取键盘输入
使用Scanner类可以很方面地获取用户的键盘输入,Scanner是一个基于正则表达式的文本扫描器,它可以从文件.输入流.字符串中解析出基本类型值和字符串值.Scanner类提供了多个构造器,不同的构 ...
- Java之三大基础排序(冒泡、选择、插入)
注:以下排序均为从小到大 一.冒泡排序 package com.yunche.testsort; import java.util.Arrays; /** * @ClassName: BubbleSo ...