HDU3555 Bomb 数位DP第一题
Now the counter-terrorist knows the number N. They want to know the final points of the power. Can you help them?
InputThe 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.
OutputFor each test case, output an integer indicating the final points of the power.Sample Input
3
1
50
500
Sample Output
0
1
15
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define LL long long
const int N=;
LL dp[N][][][],n,ans;
int a[N],cnt;
void _divide(LL v){
cnt=;
while(v){
a[++cnt]=v%;
v/=;
}return ;
}
LL _dfs(int pos,bool limit,bool pre,bool stat)
{
if(pos==) return stat;
LL tmp=;
if(!limit&&dp[pos][limit][pre][stat]) return dp[pos][limit][pre][stat];
int Up=limit?a[pos]:;
for(int i=;i<=Up;i++)
tmp+=_dfs(pos-,limit&&i==Up,i==,stat||(pre&&i==));
dp[pos][limit][pre][stat]=tmp;
if(tmp>ans) ans=tmp;
return tmp;
}
int main()
{
int i,T;
scanf("%d",&T);
while(T--){
memset(dp,,sizeof(dp));
scanf("%lld",&n);
_divide(n);
printf("lld\n",_dfs(cnt,true,false,false));
}
return ;
}
HDU3555 Bomb 数位DP第一题的更多相关文章
- hdu3555 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 Bomb Time Limit: 2000/1000 MS (Java/Others) M ...
- hdu---(3555)Bomb(数位dp(入门))
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submi ...
- 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 ...
- Bomb 数位dp
---恢复内容开始--- 不能有49 数位dp模板题: #include<bits/stdc++.h> using namespace std; //input by bxd #defin ...
- HDU 2089 不要62(数位dp模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=2089 题意:求区间内不包含4和连续62的数的个数. 思路: 简单的数位dp模板题.给大家推荐一个好的讲解博客.h ...
- 【hdu3555】Bomb 数位dp
题目描述 求 1~N 内包含数位串 “49” 的数的个数. 输入 The first line of input consists of an integer T (1 <= T <= 1 ...
随机推荐
- gTest&gMock learning
在C++中,编写服务后的一种测试方式是使用google的gTest和gMock结合 之前写py,测试方式是将服务挂起,使用工具模拟请求发包,check resp,这样的缺点在于不方便,即使存下了所有的 ...
- 使用iview--1
在任意一个你想创建项目的路径下 每次输入就输一致的就可以 /*************************安装选项开始****************/ 回车再次回车就如下,输入Y 继续 回车,输 ...
- Moment.js的一些用法
前记:项目开发用到了日历插件(Pikaday.js),同时也用到了Moment.js(日期处理类库) 1.subtract:减去,下面代码的意思是减去1天 this.yestdayStr = mome ...
- js从一个select选择数据添加到另一个select(包括移除)
一.实现效果 二.要求 1.选中左侧的菜单,点击“>>”,该菜单(1项或多项选中的)将添加到右侧菜单 2.选中右侧菜单,点击“<<”,则移除选中的菜单 3.点击“>> ...
- javascript深入浅出
第一章 数据类型 1,六种数据类型:原始类型(number,string,boolean,null,undefined) + object对象(Function Array Date) 2,隐式转换: ...
- 我的Android学习路线(二)
这两天的主要工作: 优化了一下布局界面,原本使用的是相对布局,直观省力,但是考虑了一下还是使用更加主流的线性布局. 完善了一下计算器的功能,比如加入小数运算. 使用线性布局的思路可以用下面的伪代码表示 ...
- elasticsearch 集群的安装部署
一 介绍 elasticsearch 是居于lucene的搜素引擎,可以横向集群扩展以及分片,开发者无需关注如何实现了索引的备份,集群同步,分片等,我们很容易通过简单的配置就可以启动elasticse ...
- ManualResetEvent(ManualResetEvent : EventWaitHandle : WaitHandle)的三个方法
ManualResetEvent mre= new ManualResetEvent(false);(ManualResetEvent : EventWaitHandle : WaitHandle) ...
- 转:MyEclipse安装Eclipse Memory Analyzer插件,并进行错误文件分析流程
转自 http://www.cnblogs.com/nb44c/p/5218880.html 1.先安装MAT插件 Memory Analyzer 插件下载地址:http://www.eclipse. ...
- CodeForces 297C Splitting the Uniqueness (脑补构造题)
题意 Split a unique array into two almost unique arrays. unique arrays指数组各个数均不相同,almost unique arrays指 ...