Codeforces 833 C - Ever-Hungry Krakozyabra
思路:
首先,inedible tails 的个数最多为C(18+9,9)个(用隔板法),所以我们暴力出所有的 inedible tails,然后检查一下在[L, R]这段区间是否存在这个inedible tails
检查的时候用了和数位dp差不多的方法,设一个下界和上界,只要之前的既没有达到上界也没有达到下界,后面就可以随便填了,说明存在
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head int l[], r[], f[], ans = , cnt = ;
bool check(int pos, bool Llimit, bool Rlimit) {
if(!Llimit && !Rlimit) return true;
if(pos == ) return true;
int down = Llimit ? l[pos] : ;
int up = Rlimit ? r[pos] : ;
for (int i = down; i <= up; i++) {
if(f[i]) {
f[i]--;
bool flag = check(pos-, Llimit&&i==l[pos], Rlimit&&i==r[pos]);
f[i]++;
if(flag) return true; }
}
return false;
}
void dfs(int pos, int res) {
if(pos == ) {
f[pos] = res;
if(check(cnt, , )) ans++;
return ;
}
for (int i = ; i <= res; i++) {
f[pos] = i;
dfs(pos+, res - i);
}
}
int solve(LL L, LL R) {
cnt = ;
while(L) {
l[++cnt] = L%;
L /= ;
} cnt = ;
while(R) {
r[++cnt] = R%;
R /= ;
}
ans = ;
dfs(, cnt);
return ans;
}
int main() {
LL L, R;
scanf("%lld %lld", &L, &R);
printf("%d\n", solve(L, R));
return ;
}
Codeforces 833 C - Ever-Hungry Krakozyabra的更多相关文章
- Educational Codeforces Round 34 A. Hungry Student Problem【枚举】
A. Hungry Student Problem time limit per test 1 second memory limit per test 256 megabytes input sta ...
- Codeforces Round #833 (Div. 2)补题
Codeforces Round #833 (Div. 2) D. ConstructOR 知识点:高位和对低位无影响 一开始以为和广州的M一样,是数位dp,后来发现只要找到一个就行 果然无论什么时候 ...
- codeforces hungry sequence 水题
题目链接:http://codeforces.com/problemset/problem/327/B 这道题目虽然超级简单,但是当初我还真的没有想出来做法,囧,看完别人的代码恍然大悟. #inclu ...
- Codeforces Round #191 (Div. 2) B. Hungry Sequence(素数筛选法)
. Hungry Sequence time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- codeforces 327 B. Hungry Sequence
题目链接 题目就是让你输出n个数的序列,要保证该序列是递增的,并且第i个数的前面不能保护它的约数,我直接先对前100000的素数打表,然后输出前n个,so easy. //cf 191 B #incl ...
- Codeforces Round #833 (Div. 2) A-D.md
比赛链接 A 题解 知识点:数学. 注意到 \(n\) 为奇数时,不考虑连续性,一共有 \(\lceil \frac{n}{2} \rceil ^2\) 个格子,接下来证明一定能凑成方块. 从下往上从 ...
- Codeforces Round #342 (Div. 2) A - Guest From the Past 数学
A. Guest From the Past 题目连接: http://www.codeforces.com/contest/625/problem/A Description Kolya Geras ...
- Codeforces Round #325 (Div. 2) B. Laurenty and Shop 前缀和
B. Laurenty and Shop Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/p ...
- Codeforces 833E Caramel Clouds
E. Caramel Clouds time limit per test:3 seconds memory limit per test:256 megabytes input:standard i ...
随机推荐
- 电影编码JPEG2000与H.264
电影的第三次革命是数字电影的诞生,数字电影取代了胶片,那么数字电影就一定有其独特的封装(压缩)格式.在网络上,我们经常见到许多视频格式,诸如mp4.mkv.flv.rmvb等,这些都是在通用计算机上播 ...
- Spring Boot(九):定时任务
Spring Boot(九):定时任务 一.pom包配置 pom包里面只需要引入springboot starter包即可 <dependencies> <dependency> ...
- 一次 Java 内存泄漏排查过程,涨姿势
人人都会犯错,但一些错误是如此的荒谬,我想不通怎么会有人犯这种错误.更没想到的是,这种事竟发生在了我们身上.当然,这种东西只有事后才能发现真相.接下来,我将讲述一系列最近在我们一个应用上犯过的这种错误 ...
- 批量telnet端口通不通
每读一行就运行一次telnet IP port #!/bin/bash port="22" cat *.txt | while read line do telnet ${line ...
- Oracle使用——oracle 忘记用户密码登录
背景 有时候我们忘记了oracle登录的用户密码,甚至是用户名称都不确定,应该怎么登陆呢 操作系统 CentOS7 Oracle12c 操作步骤 使用sqlplus登录系统:sqlplus / a ...
- 快速自动安装dart
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat Non ...
- 如何安装整个linux系统中所需要的mp3播放库插件? 可以在安装rpmfusion仓库后直接通过dnf install进行按照就可以了
在vi的界面中, 前面的数字, 表示一行. 而对于中文而言, 并不一定是"一个文本行"就是一行, 而是以 回车(硬回车)为标志, 来判定一行的. 而dd, yy等也是以" ...
- Docker Tomcat远程部署到容器
一:创建一个开启远程部署的tomcat容器 tomcat角色配置 1.tomcat开启远程部署,修改conf/tomcat-users.xml <?xml version="1.0&q ...
- vue项目从引入vue.js 改为使用vue-cil (webpack)时修改的一些内容
在元素属性中不要写js关键字,会报使用关键字的错如@click='if(){}else{}', if-else 语句可以使用三元表达式或短路运算符来实现 v-for 不写:key 会有警告 ,使用: ...
- Component 组件props 属性设置
props定义属性并获取属性值 html <div id="app"> <!-- 注册一个全局逐渐 --> <!-- 注意如果自定义的属性带-像下面这 ...