HDU3555 Bomb —— 数位DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555
Bomb
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 18739 Accepted Submission(s): 6929
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?
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.
题解:
数位DP通用:dp[pos][sta1][sta2][……]
表示:当前位为pos,之前的状态为sta1*sta2*……stan。n为限制条件的个数。
回到此题,限制条件有两个: 1.上一位是否为4; 2.之前是否已经出现49。
类似题目:http://blog.csdn.net/dolfamingo/article/details/72848001
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
using namespace std;
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+;
const int maxn = +; LL n;
LL a[maxn], dp[maxn][]; LL dfs(int pos, int status, bool lim)
{
if(!pos) return status==;
if(!lim && dp[pos][status]!=-) return dp[pos][status]; LL ret = ;
int m = lim?a[pos]:;
for(int i = ; i<=m; i++)
{
int tmp_status;
if(status== || status== && i==)
tmp_status = ;
else if(i==)
tmp_status = ;
else
tmp_status = ; ret += dfs(pos-, tmp_status, lim&&(i==m));
} if(!lim) dp[pos][status] = ret;
return ret;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lld",&n);
int p = ;
while(n)
{
a[++p] = n%;
n /= ;
}
memset(dp,-, sizeof(dp));
LL ans = dfs(p, , );
printf("%lld\n",ans);
}
}
HDU3555 Bomb —— 数位DP的更多相关文章
- hdu---(3555)Bomb(数位dp(入门))
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submi ...
- hdu3555 Bomb(数位dp)
题目传送门 Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total ...
- hdu3555 Bomb 数位DP入门
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 简单的数位DP入门题目 思路和hdu2089基本一样 直接贴代码了,代码里有详细的注释 代码: ...
- HDU3555 Bomb[数位DP]
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submi ...
- HDU3555 Bomb 数位DP第一题
The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the ti ...
- hdu3555 Bomb (数位dp入门题)
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submi ...
- 【hdu3555】Bomb 数位dp
题目描述 求 1~N 内包含数位串 “49” 的数的个数. 输入 The first line of input consists of an integer T (1 <= T <= 1 ...
- HDU 3555 Bomb 数位dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Mem ...
- hud 3555 Bomb 数位dp
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Subm ...
随机推荐
- 关于Boot应用中集成Spring Security你必须了解的那些事
Spring Security Spring Security是Spring社区的一个顶级项目,也是Spring Boot官方推荐使用的Security框架.除了常规的Authentication和A ...
- Nk 1214 Relatives(欧拉函数)
Time Limit: 1500 ms Memory Limit: 10000 kB Total Submit : 234 (77 users) Accepted Submit : 10 ...
- Codeforces737E. Tanya is 5!
$n \leq 40$个人玩$m \leq 10$台游戏机,每台游戏机一秒内只能一人玩,每人一秒内只能玩一台.每台游戏机有个价格,在规定总价格内可以把一部分游戏机复制一次,每台只能复制一次.给每个人对 ...
- max file descriptors [4096] for elasticsearch proess is too low, increase to at least [65536]
修改文件 /etc/security/limits.conf 加入以下两行: sonar hard nofile 65536 sonar soft nofile 65536 #备注:sonar这里是 ...
- [Bzoj1112][POI2008]砖块Klo(splay)
1112: [POI2008]砖块Klo Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2353 Solved: 831[Submit][Statu ...
- JDBC 数据库连接 Java操作数据库 jdbc快速入门
JDBC基本概念 Java DataBase Connectivity 数据库连接 java操作数据库 本质上(sun公司的程序员)定义的一套操作关系型数据库的规则 既接口 更新内容之前 代码 pa ...
- Ubuntu 16.04安装IntelliJ IDEA时快捷键冲突设置
解决快捷键冲突可以有如下方法: 1.直接修改IDEA的,但是不建议这么干,因为多平台时,或者去到另外一台电脑时,统一的快捷键能更快的适应新的开发环境. 2.通过修改系统默认的快捷键. 3.就这两种方式 ...
- Spring基于构造函数的依赖注入(DI)
以下内容引用自http://wiki.jikexueyuan.com/project/spring/dependency-injection/spring-constructor-based-depe ...
- VS2017不能生成Database Unit Test项目
问题描述: VS2017生成Database Unit Test项目时,报出如下错误,但该项目在VS2015中能正常生成: 主要是因为下面两个程序集找不到引用: Microsoft.Data.Tool ...
- 【mac】mac上安装JDK
安装步骤就是在Oracle官网下载你想要的JDK版本下载,下载的时候同意协议即可 这里就给出jdk安装的位置 还有一点要注意的是,在指定JVM的位置的时候,需要指定到home目录下