[暑假集训--数位dp]hdu2089 不要62
杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍,更安全地服务大众。
不吉利的数字为所有含有4或62的号码。例如:
62315 73418 88914
都属于不吉利号码。但是,61152虽然含有6和2,但不是62连号,所以不属于不吉利数字之列。
你的任务是,对于每次给出的一个牌照区间号,推断出交管局今次又要实际上给多少辆新的士车上牌照了。
0 0
数位dp
要记一下上一位是不是6
#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 l,r,len;
LL f[][];
int d[];
inline int dfs(int now,int lst,int fp)
{
if (now==)return ;
if (!fp&&f[now][lst]!=-)return f[now][lst];
LL ans=,mx=(fp?d[now-]:);
for (int i=;i<=mx;i++)
{
if (lst==&&i==||i==)continue;
ans+=dfs(now-,i,fp&&mx==i);
}
if (!fp&&f[now][lst]==-)f[now][lst]=ans;
return ans;
}
inline LL calc(LL x)
{
if (x==-)return ;
if (x==)return ;
LL xxx=x;
len=;
while (xxx)
{
d[++len]=xxx%;
xxx/=;
}
LL sum=;
for (int i=;i<=d[len];i++)
if (i!=)sum+=dfs(len,i,i==d[len]);
return sum;
}
int main()
{
memset(f,-,sizeof(f));
while (~scanf("%d%d",&l,&r)&&l+r)printf("%lld\n",calc(r)-calc(l-));
}
hdu 2089
#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=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
LL n,len;
LL f[20][13][10][2];
int d[20];
inline int dfs(int now,int rest,int dat,int sat,int fp)
{
if (now==1)return !rest&&sat;
if (!fp&&f[now][rest][dat][sat]!=-1)return f[now][rest][dat][sat];
LL ans=0,mx=(fp?d[now-1]:9);
for (int i=0;i<=mx;i++)
{
if (sat||!sat&&dat==1&&i==3)ans+=dfs(now-1,(rest*10+i)%13,i,1,fp&&mx==i);
else ans+=dfs(now-1,(rest*10+i)%13,i,0,fp&&mx==i);
}
if (!fp&&f[now][rest][dat][sat]==-1)f[now][rest][dat][sat]=ans;
return ans;
}
inline LL calc(LL x)
{
LL xxx=x;
len=0;
while (xxx)
{
d[++len]=xxx%10;
xxx/=10;
}
LL sum=0;
for (int i=0;i<=d[len];i++)
sum+=dfs(len,i,i,0,i==d[len]);
return sum;
}
int main()
{
memset(f,-1,sizeof(f));
while (scanf("%d",&n)!=EOF)printf("%lld\n",calc(n));
}
[暑假集训--数位dp]hdu2089 不要62的更多相关文章
- [暑假集训--数位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]hdu3555 Bomb
The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the ti ...
- [暑假集训--数位dp]hdu3652 B-number
A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- ...
- [暑假集训--数位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 ...
随机推荐
- 洛谷 P1276 校门外的树(增强版)
题目描述 校门外马路上本来从编号0到L,每一编号的位置都有1棵树.有砍树者每次从编号A到B处连续砍掉每1棵树,就连树苗也不放过(记 0 A B ,含A和B):幸运的是还有植树者每次从编号C到D 中凡是 ...
- poj1142Smith Numbers质因子分解
题意:一个数不是质数,其质因子的每位加起来等于该数的每位加起来. /* 题意:一个数的所有质因子的每位相加起来等于该数的每位相加起来且该数不能是质数,那么就是史密斯数 tip:对于分解质因子,只需要判 ...
- 用”人话”解释CNN —— 对单个特征图进行视觉化
转载自:http://nooverfit.com/wp/pycon-2016-tensorflow-研讨会总结-tensorflow-手把手入门-用人话解释cnn 首先什么是CNN? 其实, 用”人话 ...
- python基础一 day13 生成器
#生成器函数# def generator():# print(1)# return 'a'## ret = generator()# print(ret) #只要含有yield关键字的函数都是生成器 ...
- 一、numpy入门
Array import numpy as np # create from python list list_1 = [1, 2, 3, 4] array_1 = np.array(list_1)# ...
- viewDidLoad、viewWillAppear、viewWillDisappear
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil viewDidLo ...
- TCP/IP各种数据包结构体
下面这些TCP/IP数据包是我在进行Socket及Wipcap网络编程过程中曾经用到过的数据包结构体, 这些东西平时看起来不起眼,真正用到的时候就会觉得非常有用...... 以太帧头格式结构体,共14 ...
- python私有成员与公有成员(_和__)
python并没有对私有成员提供严格的访问保护机制. 在定义类的成员时,如果成员名以两个下划线“__”或更多下划线开头而不以两个或更多下划线结束则表示是私有成员. 私有成员在类的外部不能直接访问,需要 ...
- MySQL中常见的锁
一.按读写方式分类 1.读锁又称共享锁,读锁是共享的,读锁之间是互不阻塞. 2.写锁又称排他锁,写锁是排他的,写锁会阻塞其他读锁和写锁 二.按锁的粒度分类 1.表锁是MySQL中最基本的锁策略,该锁的 ...
- perl学习之内置变量
Perl内置特殊变量 一.正则表达式特殊变量:1.$n :包含上次模式匹配的第n个子串2.$& :前一次成功模式匹配的字符串3.$` :前次匹配成功的子串之前的内容4.$’ :前次匹配 ...