E. Ever-Hungry Krakozyabra

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

Recently, a wild Krakozyabra appeared at Jelly Castle. It is, truth to be said, always eager to have something for dinner.

Its favorite meal is natural numbers (typically served with honey sauce), or, to be more precise, the zeros in their corresponding decimal representations. As for other digits, Krakozyabra dislikes them; moreover, they often cause it indigestion! So, as a necessary precaution, Krakozyabra prefers to sort the digits of a number in non-descending order before proceeding to feast. Then, the leading zeros of the resulting number are eaten and the remaining part is discarded as an inedible tail.

For example, if Krakozyabra is to have the number 57040 for dinner, its inedible tail would be the number 457.

Slastyona is not really fond of the idea of Krakozyabra living in her castle. Hovewer, her natural hospitality prevents her from leaving her guest without food. Slastyona has a range of natural numbers from L to R, which she is going to feed the guest with. Help her determine how many distinct inedible tails are going to be discarded by Krakozyabra by the end of the dinner.

Input

In the first and only string, the numbers L and R are given – the boundaries of the range (1 ≤ L ≤ R ≤ 1018).

Output

Output the sole number – the answer for the problem.

Examples
Input
1 10
Output
9
Input
40 57
Output
17
Input
157 165
Output
9
Note

In the first sample case, the inedible tails are the numbers from 1 to 9. Note that 10 and 1 have the same inedible tail – the number 1.

In the second sample case, each number has a unique inedible tail, except for the pair 45, 54. The answer to this sample case is going to be (57 - 40 + 1) - 1 = 17.

题目链接:http://codeforces.com/contest/834/problem/E

官方题解:

下面给出AC代码:

 #include <iostream>
#include <cstring>
#include <climits> const int N = ; using LL = int64_t; int a[N], b[N], c[], cc[]; bool check(int i, int need, bool gt, bool lt)
{
if (gt && lt) {
return need <= N - i;
}
if (i == N || need > N - i) {
return false;
}
for (int d = gt ? : a[i]; d <= (lt ? : b[i]); ++ d) {
cc[d] ++;
if (cc[d] <= c[d] && check(i + , need - !!d, gt || a[i] < d, lt || d < b[i])) {
return true;
}
cc[d] --;
}
return false;
} int search(int d, int used)
{
if (d == ) {
memset(cc, , sizeof(cc));
return check(, used, false, false);
}
int result = ;
for (c[d] = ; used + c[d] <= N - ; ++ c[d]) {
result += search(d + , used + c[d]);
}
return result;
} int main()
{
#ifdef LOCAL_JUDGE
freopen("C.in", "r", stdin);
#endif
LL l, r;
while (std::cin >> l >> r) {
l --, r ++;
for (int i = N - ; i >= ; -- i) {
a[i] = l % , b[i] = r % ;
l /= , r /= ;
}
c[] = INT_MAX;
printf("%d\n", search(, ));
}
}

Codeforces 834E The Bakery【枚举+数位dp】的更多相关文章

  1. CF1277A. Happy Birthday, Polycarp! 题解 枚举/数位DP

    题目链接:http://codeforces.com/contest/1277/problem/A 题目大意: 求区间 \([1,n]\) 范围内有多少只包含一个数字的数. 比如:\(1,77,777 ...

  2. Codeforces 1290F - Making Shapes(数位 dp)

    Codeforces 题面传送门 & 洛谷题面传送门 数位 dp 好题. 首先,由于是凸包,一但向量集合确定,凸包的形态肯定就已经确定了.考虑什么样的向量集合能够组成符合条件的凸包,我们假设第 ...

  3. CodeForces 55D "Beautiful numbers"(数位DP+离散化处理)

    传送门 参考资料: [1]:CodeForces 55D Beautiful numbers(数位dp&&离散化) 我的理解: 起初,我先定义一个三维数组 dp[ i ][ j ][ ...

  4. BZOJ 1799 - [AHOI2009]self 同类分布 - 枚举 数位DP

    Description 找出$[L, R]$ 区间内有多少数, 各位数字和 能整除原数 Solution 枚举每个可能的数字和, 进行数位DP即可 , 水爆 Code #include<cstd ...

  5. CodeForces 55D Beautiful numbers(数位dp+数学)

    题目链接:http://codeforces.com/problemset/problem/55/D 题意:一个美丽数就是可以被它的每一位的数字整除的数. 给定一个区间,求美丽数的个数. 显然这是一道 ...

  6. Codeforces 55D. Beautiful numbers(数位DP,离散化)

    Codeforces 55D. Beautiful numbers 题意 求[L,R]区间内有多少个数满足:该数能被其每一位数字都整除(如12,24,15等). 思路 一开始以为是数位DP的水题,觉得 ...

  7. Codeforces Gym 100418J Lucky tickets 数位DP

    Lucky ticketsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...

  8. CodeForces 55D Beautiful numbers(数位dp)

    数位dp,三个状态,dp[i][j][k],i状态表示位数,j状态表示各个位上数的最小公倍数,k状态表示余数 其中j共有48种状态,最大的是2520,所以状态k最多有2520个状态. #include ...

  9. CodeForces 628 D Magic Numbers 数位DP

    Magic Numbers 题意: 题意比较难读:首先对于一个串来说, 如果他是d-串, 那么他的第偶数个字符都是是d,第奇数个字符都不是d. 然后求[L, R]里面的多少个数是d-串,且是m的倍数. ...

随机推荐

  1. 【JMeter】source("文件路程")和${变量}同时出现会报错

    source("D:\\apache-jmeter-3.0\\testcase\\java\\Test.java"); //${journeyLen} 以上两句在JMeter脚本里 ...

  2. iOS Swift3.0 OC 数据储存--归档

    一.Swift 3.0 1.model class userModel: NSObject,NSCoding { var account: String = "" var regm ...

  3. Inception使用详解

    一.Inception简介一款用于MySQL语句的审核的开源工具,不但具备自动化审核功能,同时还具备执行.生成对影响数据的回滚语句功能. 基本架构: 二.Inception安装 1.软件下载 下载链接 ...

  4. SpringMVC总结

    本文是对慕课网上"搞定SSM开发"路径的系列课程的总结,详细的项目文档和课程总结放在github上了.点击查看 MVC简介 Model-View-Control,MVC是一种架构模 ...

  5. jsp上的九个隐含对象

    首先说一说件jsp的原理.jsp被认为最经典的解释是  “嵌入了java 代码的html”. 在网上查了一些资料,和我本身对jsp的认识,总结如下: jsp本质上是一个servlet,继承自 当第一次 ...

  6. bzoj 4013: [HNOI2015]实验比较

    Description 小D 被邀请到实验室,做一个跟图片质量评价相关的主观实验.实验用到的图片集一共有 N 张图片,编号为 1 到 N.实验分若干轮进行,在每轮实验中,小 D会被要求观看某两张随机选 ...

  7. laravel框架一种方便的快速填充数据的方法

    首先大家都知道在laravel框架里是采用seeder来填充数据的,具体命令如下,请将如下的类名称替换成你具体的seeder类名. 首先创建seeder类 php artisan make:seede ...

  8. Mac下持久化路由配置

    缘由 mac 下有个小命令,networksetup,之前电脑装了IKEv2 的VPN,每天能正常FQ,由于所有流量都走了VPN隧道,导致了公司内部的其它网络无法访问得到,必须每次的来回拨VPN,断V ...

  9. PHP 微信公众号-创建菜单-配置

    1.服务号 2.基本配置 注意: URL: 确保能访问到你对应的文件 Token:随意设置,但是要与文件里的一致 3.网页授权 注意:填写网站域名 4.更具实际需求创建菜单

  10. Docker三十分钟快速入门(上)

    一.背景 ​ 最近,Docker技术真是一片火热,它的出现也弥补了虚拟机资源消耗过高的问题,直接让虚拟化技术有了质的飞跃.那么本文我们来聊一聊Docker,和大家一起认识Docker,简单入门Dock ...