D - Bomb
//反向62
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
using namespace std; typedef long long ll;
// const int maxn = 1e5+5;
ll n;
ll a[];
ll dp[][]; //下标,前面是否4,是否有前导0, 是否有限制
ll dfs(ll pos, ll sta, ll pre, ll limit){
if(pos == -) return ;
if(!limit && dp[pos][sta] != -)
return dp[pos][sta];
int up = limit?a[pos]:;
ll ans = ;
for(int i = ;i <= up;i++){
if(pre == && i == ){
continue;
}
ans += dfs(pos-, i == , i, limit && i == a[pos]);
}
if(!limit) dp[pos][sta] = ans;
return ans;
} ll solve(ll x){
ll pos = ;
while(x){
a[pos++] = x%;
x /= ;
}
return dfs(pos-, , -, true);
} int main(){
memset(dp, -, sizeof dp);
int t;
scanf("%d", &t);
while(t--){
scanf("%lld", &n);
ll ans = solve(n);
printf("%lld\n", n - ans + );
}
return ;
}
D - Bomb的更多相关文章
- HDU3555 Bomb[数位DP]
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submi ...
- Leetcode: Bomb Enemy
Given a 2D grid, each cell is either a wall 'W', an enemy 'E' or empty '0' (the number zero), return ...
- HDU 5934 Bomb(炸弹)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- hdu 3622 Bomb Game(二分+2-SAT)
Bomb Game Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- Bomb
Description The counter-terrorists found a time bomb in the dust. But this time the terrorists impro ...
- CF 363B One Bomb(枚举)
题目链接: 传送门 One Bomb time limit per test:1 second memory limit per test:256 megabytes Description ...
- hdu3555 Bomb (记忆化搜索 数位DP)
http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Memory ...
- [HDU3555]Bomb
[HDU3555]Bomb 试题描述 The counter-terrorists found a time bomb in the dust. But this time the terrorist ...
- hdu 5934 Bomb
Bomb Problem Description There are N bombs needing exploding.Each bomb has three attributes: explodi ...
- HDOJ 3555 Bomb
数位DP的DFS写法.... Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Oth ...
随机推荐
- DuiLib笔记之Control常用属性
name 指定控件名称,同一窗口内必须唯一,类型:STRING float 用于指定控件是否使用绝对定位,或设置FloatPercent,类型:BOOL,默认值为false,格式:float=&quo ...
- Post Man 调用CRMAPI
官方文档 https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/webapi/setup-postman ...
- xcode7和ios9下UIWebView不能加载网页的解决方法
错误描述: App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecu ...
- Android Studio 模拟器无法打开 emulator: ERROR: x86 emulation currently requires hardware
首先要打开SDK的下载位置,找到以下陌路: android-sdk\extras\intel\Hardware_Accelerated_Execution_Manager\IntelHaxm.exe ...
- android studio导入项目出现的奇葩错误
1.Error:(1, 0) Cause: com/android/build/gradle/AppPlugin : Unsupported major.minor version 52.0
- java中的break与continue
1.两者的作用 break:是跳出当前的循环块或者程序块.循环块有for.do while.while,程序块有switch(){case 1: xxx;break;}在循环体中的作用是跳出正在循环的 ...
- Android 启动过程介绍【转】
本文转载自:http://blog.csdn.net/yangwen123/article/details/8023654 一般开机过程大致可以分为三个大阶段: 1. OS级别,由bootloader ...
- ansible安全优化建议
摘自 ansible自动化配置书籍,特此感谢 针对非授权连接和截取通信息等共计行为,我们总结了9条方法: 使用安全加密的通信方式 禁止root用户远程登录并充分利用sudo 移除非必须的软件,只开放需 ...
- Java内存模型(JMM)中的happens-before
happens-before是JMM中最核心的概念,对于Java程序员来说,理解happens-before是理解JMM的关键 . 1.JMM的设计 首先,来看看JMM的设计意图.从JMM的设计者的角 ...
- cnn汉字识别 tensorflow demo
# -*- coding: utf-8 -*- import tensorflow as tf import os import random import tensorflow.contrib.sl ...