[暑假集训--数位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 ...
随机推荐
- centos中安装elasticsearch5.0
1.安装jdk 可以直接安装自带的openjdk,安装完成之后修改一下java的环境变量.另一种方式是就是安装oracle的jdk,从官网上下载http://www.oracle.com/techne ...
- 更新Svn客户端后,右键菜单中没有TortoiseSVN
环境: OS: Windows XP sp3 升级后SVNServer: VisualSVN Server 2.7.3 升级后SVNClient: 小乌龟: ...
- mac上使用命令行显示隐藏文件
终端中输入命令 打开<终端> - 粘贴下面的两行命令执行 defaults write com.apple.finder AppleShowAllFiles TRUEkillall Fin ...
- jQuery筛选器及练习
jQuery初识 jQuery是什么? jQuery是一个兼容多浏览器的JavaScript库. jQuery能极大地简化JavaScript编程,它的宗旨就是:"Write less, ...
- [JOYOI] 1035 棋盘覆盖
题目限制 时间限制 内存限制 评测方式 题目来源 1000ms 131072KiB 标准比较器 Local 题目描述 给出一张nn(n<=100)的国际象棋棋盘,其中被删除了一些点,问可以使用多 ...
- mysql基本优化
文件打开数 show status like "%Open_files%" Open_files 133 show VARIABLES like "%open_files ...
- (3)zabbix用户管理
登陆zabbix 默认账号:Admin,密码:zabbix,这是一个超级管理员.登陆之后在右下角可以看到“connected as Admin“(中文版:连接为Admin). zabbix组介绍 我们 ...
- js中小数精度问题
js中小数的取值为近似值,可能比实际值大,也可能比实际值小,进行“四舍五入”得到的 例如:alert(0.1+0.2);值为0.300000004 alert(0.2+0.7);值为1.899 ...
- Python3与SQLServer、Oracle、MySql的连接方法
环境: python3.4 64bit pycharm2018社区版 64bit Oracle 11 64bit SQLServer· Mysql 其中三种不同的数据库安装在不同的服务器上,通过局域网 ...
- LeetCode(79) Word Search
题目 Given a 2D board and a word, find if the word exists in the grid. The word can be constructed fro ...