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 ...
随机推荐
- 05_zookeeper_原生API使用1(更新)
1. java方式操作远端zookeeper集群概述 步骤:下载zookeeper压缩包并解压, 创建java工程,导入zookeeper相关jar包 (1)下载zookeeper压缩包 http:/ ...
- jQuery实际案例⑥——图片跟随鼠标、五角星评分案例
一.图片跟随鼠标移动 1.要求:鼠标移动到哪,图片就要跟到哪 2.用到的事件:首先监听鼠标:$(document).mousemove(function(event){ }); //此时可以获取鼠标距 ...
- TCP_DB_中间件_数据打包格式
ZC: 这里约定的是,C和S之间 传输的TCP数据包的格式 1.TCP数据包 打包格式 1.1.TCP包长度(int32) + TCP包序号(int32) + TCP包类型(int32) + TCP包 ...
- 先安装ubuntu,后安装windows,修复启动grub
使用easybcd修复未果,直接使用启动盘修复,主要根据这个帖子来的,验证可用 http://blog.csdn.net/kevin6216/article/details/7764292 由于重装w ...
- 设计模式--命令模式C++实现
命令模式C++实现 1定义 将一个请求封装成一个对象,从而让你使用不同的请求把客户端参数化,对请求队列或者记录请求日志,可以提供命令的撤销和恢复功能 2类图 角色描述: Receiver接受者角色,就 ...
- asp.net服务器上无法发送邮件的问题
前几天为开发的网站做了个发送邮件的功能,但是部署到服务器上无法发送邮件,提示由于目标机器积极拒绝,无法连接.在网上找到了一个解决办法 如果安装了McAfee杀毒软件(按照“手工安装方法”安装),首先需 ...
- IOS UI-自定义UIColectionView布局
ViewController.m // // ViewController.m // IOS_0226_自定义UIColectionView布局 // // Created by ma c on 16 ...
- JavaScript---forEach( ) 、map( )和 filter()
循环数组,最先想到的就是for循环: for(var i=0;i<count;i++) { //逻辑代码} 除此之外,就是forEach()方法了. Firefox 和Chrome 的Arra ...
- Windows 下 左Ctrl和Caps交换
将以下文本存为后缀为.reg文件,运行并重启即可 左Ctrl和Caps交换 Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTE ...
- LeetCode OJ:Sudoku Solver(数独游戏)
Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...