[暑假集训--数位dp]hdu3555 Bomb
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,找子序列‘49’
记一下有没有出现过'4',是否已经出现过"49"
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
LL n,len;
LL f[][][];
int d[];
inline LL dfs(int now,int dat,int sat,int fp)
{
if (now==)return sat;
if (!fp&&f[now][dat][sat]!=-)return f[now][dat][sat];
LL ans=,mx=(fp?d[now-]:);
for (int i=;i<=mx;i++)
{
if (sat||!sat&&dat==&&i==)ans+=dfs(now-,i,,fp&&mx==i);
else ans+=dfs(now-,i,,fp&&mx==i);
}
if (!fp&&f[now][dat][sat]==-)f[now][dat][sat]=ans;
return ans;
}
inline LL calc(LL x)
{
LL xxx=x;
len=;
while (xxx)
{
d[++len]=xxx%;
xxx/=;
}
LL sum=;
for (int i=;i<=d[len];i++)
sum+=dfs(len,i,,i==d[len]);
return sum;
}
int main()
{
memset(f,-,sizeof(f));
int T=read();
while (T--)n=read(),printf("%lld\n",calc(n));
}
hdu 3555
[暑假集训--数位dp]hdu3555 Bomb的更多相关文章
- [暑假集训--数位dp]LightOj1205 Palindromic Numbers
A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...
- [暑假集训--数位dp]hdu3709 Balanced Number
A balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. ...
- [暑假集训--数位dp]hdu3652 B-number
A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- ...
- [暑假集训--数位dp]hdu2089 不要62
杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍, ...
- [暑假集训--数位dp]hdu5787 K-wolf Number
Alice thinks an integer x is a K-wolf number, if every K adjacent digits in decimal representation o ...
- [暑假集训--数位dp]UESTC250 windy数
windy定义了一种windy数. 不含前导零且相邻两个数字之差至少为22 的正整数被称为windy数. windy想知道,在AA 和BB 之间,包括AA 和BB ,总共有多少个windy数? Inp ...
- [暑假集训--数位dp]LightOJ1140 How Many Zeroes?
Jimmy writes down the decimal representations of all natural numbers between and including m and n, ...
- [暑假集训--数位dp]LightOj1032 Fast Bit Calculations
A bit is a binary digit, taking a logical value of either 1 or 0 (also referred to as "true&quo ...
- [暑假集训--数位dp]hdu5898 odd-even number
For a number,if the length of continuous odd digits is even and the length of continuous even digits ...
随机推荐
- Maven settings.xml配置详解
首先:Maven中央仓库的搜索全部公共jar包的地址是,http://search.maven.org/ ===Maven基础-默认中央仓库============================== ...
- 【转】Intellij IDEA 提交代码到远程GitHub仓库
1.文章参考自:http://my.oschina.net/lujianing/blog/180728 2.设置相关绑定 Settings——Version Control——Git——Path to ...
- Dojo中的选择器
dom.byId(以前的dojo.byId):等同于js中的document.getElementById. http://www.cnblogs.com/tiandi/archive/2013/11 ...
- java基础—泛型
一.体验泛型 JDK1.5之前的集合类中存在的问题——可以往集合中加入任意类型的对象,例如下面代码: 1 package cn.gacl.generic.summary; 2 3 import jav ...
- Java第十二次作业:继承与抽象类解决工人与学生的问题,抽象类实例。抽象类作用——为多态创造了可能。抽象类的作用总结
继承与抽象类解决工人与学生的问题 抽象类实例 package com.swift; public abstract class Person { private String name; privat ...
- redis学习笔记(2)
redis学习笔记第二部分 --配置文件介绍 二,解析redis的配置文件redis.conf常见配置参数说明redis.conf 配置项说明如下:1. Redis默认不是以守护进程的方式运行,可以通 ...
- LeetCode945-使数组唯一的最小增量
问题:使数组唯一的最小增量 给定整数数组 A,每次 move 操作将会选择任意 A[i],并将其递增 1. 返回使 A 中的每个值都是唯一的最少操作次数. 示例 1: 输入:[1,2,2] 输出:1 ...
- ACM Changchun 2015 L . House Building
Have you ever played the video game Minecraft? This game has been one of the world's most popular ga ...
- build.xml: 21: Class not found: javac1.8
在eclipse里运用ant时经常碰到class not found的错误提示,从而编译失败,其实是eclipse中本身的ant版本太老造成该的,但我今天安装的ant是1.8.4,感觉已经很新了,但编 ...
- Android CTS - Cannot run program "aapt"/ Fail to run aapt on .../apk installed but AaptParser failed
今天同事碰到cts的一些问题,跑到某个apk的时候,就提示如下错误: Cannot run program "aapt": error=2. No such file or dir ...