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 ...
随机推荐
- P3380 【模板】二逼平衡树(树套树)(线段树套平衡树)
P3380 [模板]二逼平衡树(树套树) 前置芝士 P3369 [模板]普通平衡树 线段树套平衡树 这里写的是线段树+splay(不吸氧竟然卡过了) 对线段树的每个节点都维护一颗平衡树 每次把给定区间 ...
- Android之udp传输
注意除了添加Internet权限外,还要添加两行代码 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDi ...
- day 27 异常处理
一.异常 1.什么是异常? 异常指的是与正常情况不同在程序中 程序的正常执行过程 按照代码顺序 一行一行的执行 直到所有的代码都执行完如果在执行过程中出现了错误导致代码无法执行完毕 这就称之为异常异常 ...
- 打造性感好用的 VS Code 编辑器
官网: https://code.visualstudio.com/ Blog链接:打造性感好用的VS Code编辑器 主命令框 F1或Ctrl+Shift+P: 打开命令面板.在打开的输入框内,可以 ...
- 源码编译安装libtool工具
1. 获取源码 wget http://ftpmirror.gnu.org/libtool/libtool-2.4.6.tar.gz tar xvf libtool-2.4.6.tar.gz -C ~ ...
- oracle 之 基础操作
//删除存在的表空间及数据 drop tablespace TS_YYGL including contents and datafiles 若是出现了提示 错误 导致无法全部删除,那么就执行以下语句 ...
- [easyui] - 在easyui的table中展示提示框
因为在easyui的table中字段过多,而无法展示全时,被迫只能使用这个方法. 使用方式: 在 $('#dg').datagrid({ 后的 queryParams: form2Json('sear ...
- [午间休息] - 午间codewars活跃脑袋
https://www.codewars.com/kata/51f2b4448cadf20ed0000386/javascript 中午是一个易困的时间段.如果其它人不睡觉还好. 这个js题目就是说如 ...
- Ubuntu 安装 matplotlib
参考: ubuntu16 安装matplotlib Ubuntu 安装 matplotlib sudo apt-get install libpng-dev libfreetype6-dev pkg- ...
- Qt打包
先在Qt Creator里release一遍,打开Qt下载时自带的像命令控制台一样的东西,比如我在创建项目时选用的是MinGw编译器, 然后在文件管理器里找到release生成的exe,cd进exe所 ...