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 ...
随机推荐
- Spring Boot 2 (七):Spring Boot 如何解决项目启动时初始化资源
Spring Boot 2 (七):Spring Boot 如何解决项目启动时初始化资源 在项目启动的时候需要做一些初始化的操作,比如初始化线程池,提前加载好加密证书等.今天就给大家介绍一个 Spri ...
- GitHub客户端使用
GitHub客户端使用 我们今天先讲解一下Github for windows(客户端)的使用方法,之后我们会以一个实例一步一步的来讲解Github. Github for windows(客户端)是 ...
- 06: mysql索引查找原理及调优
MySQL其他篇 目录: 1.1 常见查找方法举例 1.2 索引数据结构设相关的计算机原理 1.3 MyISAM实现索引 1.4 InnoDB索引实现 1.5 索引使用策略 1.1 常见查找方法举例返 ...
- linux 文件同步
ref: https://www.cnblogs.com/MacoLee/p/5633650.html https://wenda.so.com/q/1505308236213470 http://b ...
- RMAN入门——简介
RMAN(Recovery Manager) 1.简介 RMAN(Recovery Manager)是随Oracle服务器软件一同安装的工具软件,它可以用来备份和恢复数据库文件.归档日志和控制文件 ...
- Eclipse中手动清理项目缓存,
用过Eclipse或MyEclipse的小伙伴肯定遇到过这种情况: 代码出错后,在前台访问出问题.然后把代码改好,已经检查不到错误,可是项目在前台访问还是有问题. 这个时候,可能就是Eclipse/M ...
- CTF-逆向工程实验吧Just Click
题目链接:http://www.shiyanbar.com/ctf/1889 步骤一:PEID解析:如下图所示 步骤二:打开exe,这种类型的东西用OD打不开,想了一下,这种东西应该是C#做的,用.n ...
- ubuntu 容器安装ping ifconfig ip命令
进入容器测试ifconfig ping 没有-------->>很尴尬 apt-get install net-tools ### ifconfig apt-get install ...
- topcoder srm 305 div1
problem1 link 直接按照题意模拟即可. import java.util.*; import java.math.*; import static java.lang.Math.*; pu ...
- python&django 常见问题及解决方法
0.python-dev安装(ubuntu) apt-get install python-dev 1.Open(filename,mode) 报错实例: f = open('d:\Users\16 ...