hdu 3555 Bomb ( 数位DP)
Bomb
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 7926 Accepted Submission(s): 2780
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[i][1]表示不含49且高位为9的个数;
dp[i][2]表示包括49的个数;
dp[i][0]=10*dp[i-1][0]-dp[i-1][1]; //不含49的数能够随意加10个数字。减去9前面加4的个数
dp[i][1]=dp[i-1][0]; //不含49的数最高位加9
dp[i][2]=dp[i-1][2]*10+dp[i-1][i]; //包括49的数字能够加入0~9,高位为9的能够加4;
#include"stdio.h"
#include"string.h"
#include"iostream"
#include"algorithm"
#include"math.h"
#include"vector"
using namespace std;
#define LL __int64
#define N 25
LL dp[N][3];
void inti()
{
memset(dp,0,sizeof(dp));
dp[0][0]=1;
int i;
for(i=1; i<N; i++)
{
dp[i][0]=dp[i-1][0]*10-dp[i-1][1];
dp[i][1]=dp[i-1][0];
dp[i][2]=dp[i-1][2]*10+dp[i-1][1];
}
}
LL work(LL x)
{
int i,k,flag;
int a[N];
LL ans;
k=0;
while(x)
{
a[++k]=x%10;
x/=10;
}
a[k+1]=ans=flag=0;
for(i=k; i>0; i--)
{
ans+=a[i]*dp[i-1][2];
if(flag)
ans+=a[i]*dp[i-1][0];
else
{
if(a[i]>4)
ans+=dp[i-1][1];
}
if(a[i+1]==4&&a[i]==9)
flag=1;
// printf("%d\n",ans);
}
return ans;
}
int main()
{
int T;
LL n;
inti();
scanf("%d",&T);
while(T--)
{
scanf("%I64d",&n);
printf("%I64d\n",work(n+1));
}
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 ...
随机推荐
- Python线程同步
线程执行 join与setDaemon 子线程在主线程运行结束后,会继续执行完,如果给子线程设置为守护线程(setDaemon=True),主线程运行结束子线程即结束: 如果join()线程,那么主线 ...
- checkbox jquery操作总结
$('input[name="myCheckbox"]').prop('checked','true'); // 全选 $('input[name="myCheckbox ...
- SpringMVC(二七) 自定义视图
可以参考博客http://www.cnblogs.com/parryyang/p/5683600.html,举例很清晰. 对自定义的视图名称匹配不同的解析器进行解析. 作用:自己定义视图,视图继承vi ...
- 【SQL】SQL整表复制
SQL Server中,如果目标表存在: 1 insert into 目标表 select * from 原表; SQL Server中,如果目标表不存在: 1 select * into 目标表 f ...
- AS安装过程中出现的错误
1.首先是You may need to adjust the proxy settings in Gradle.的错误, 主要是看你有没有图中红线所画的gradle的压缩包 如果没有,那就前往htt ...
- ELK日志分析方案
针对公司项目微服务化,随着项目及服务器的不断增多,决定采用ELK(Elasticsearch+Logstash+Kibana)日志分析平台进行微服务日志分析. 1.ELK整体方案 1.1 ELK架构图 ...
- SpringCloud Gateway入门
本文是介绍一下SpringCloud Gateway简单路由转发使用. SpringCloud Gateway简介 SpringCloud是基于Spring Framework 5,Project R ...
- 页面嵌入iframe那些事儿
一.用iframe如何把别人的页面嵌入自己的页面? <iframe src="http://blog.sina.com.cn/abc" frameBorder=0 scrol ...
- sql语句(一)— —判断是否有这条数据的优化
今天发现一个业务上的存储过程写的不够完善,和老板反应后,老板说你来完善吧,我:苦瓜脸~.说实话,我对SQL语句的熟练程度真的是不提也罢[捂脸],大概的判断流程我知道,但是真的让我自己写,还真得上网查查 ...
- 03爬虫 爬取hfutxc成绩
#-*- coding:utf-8 -*- # -*- coding: utf-8 -*- #encoding:utf-8 import urllib import urllib2 import co ...