bzoj3917: [Baltic2014]sequence
Description
Input
Output
当确定了N的个位时,可以确定这连续的K个数的个位,这是得到子问题求N/10的值,B数组(压位表示子问题中哪些位必须出现)对应更新为大约K/10的长度,于是可以递归处理,当K=1时贪心确定所需的最高位
当K=2时若选择个位为9则递归下去K仍为2,要特判剪枝一下
递归到K=1时,若答案有必须存在的前导0则要特判在前面补位
#include<cstdio>
typedef long long i64;
int _(){
int x=,c=getchar();
while(c<)c=getchar();
while(c>)x=x*+c-,c=getchar();
return x;
}
int n,v[],d[];
i64 dfs(int*d0,int n,bool _9,bool _0){
bool dd=;
for(int i=;i<n;++i)if(d0[i]){dd=;break;}
if(!dd)return _0;
if(n==){
int x=*d0;
if(x==)x=;
i64 v=;
for(int i=;i<;++i)if(x>>i&){
v=i;
x^=<<i;
break;
}
for(int i=;i<;++i)if(x>>i&)v=v*+i;
return v;
}
i64 v0=1ll<<;
int*d1=d0+n;
for(int a=;a<;++a){
if(a==&&!_9)break;
int n1=,x=a,s=;
for(int b=;b<n;++b){
s|=d0[b]&~(<<x);
if(++x==){
x=;
d1[n1++]=s;
s=;
}
}
if(x)d1[n1++]=s;
i64 v1=dfs(d1,n1,a!=||n>,!a&&(_0||(&*d0)))*+a;
if(v1<v0)v0=v1;
}
return v0;
}
int main(){
n=_();
for(int i=;i<n;++i)d[i]=<<(v[i]=_());
printf("%lld",dfs(d,n,,));
return ;
}
bzoj3917: [Baltic2014]sequence的更多相关文章
- Baltic2014 sequence
问题描述 输入格式 输出格式 一个整数R 样例输入 7 9 4 8 20 14 15 18 样例输出 13 数据范围 所求的Z序列为6,7,8,13,14,15,18. R=13 解析&左偏树 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- oracle SEQUENCE 创建, 修改,删除
oracle创建序列化: CREATE SEQUENCE seq_itv_collection INCREMENT BY 1 -- 每次加几个 STA ...
- Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等
功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...
- DG gap sequence修复一例
环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Sequence Reconstruction 序列重建
Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列
Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...
随机推荐
- spring和redis的整合-超越昨天的自己系列(7)
超越昨天的自己系列(7) 扯淡: 最近一直在慢慢多学习各个组件,自己搭建出一些想法.是一个涉猎的过程,慢慢意识到知识是可以融汇贯通,举一反三的,不过前提好像是研究的比较深,有了自己的见解.自认为学习 ...
- .net利用本地播放器播放视频文件代码
前台点击按钮,执行js事件,跳转到后台代码: function funShowVideo(index) { var iTop = (window.screen.availHeig ...
- 112. Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...
- 7. Reverse Integer java
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 代码如下: pub ...
- android listview去掉分割线
1:android listview去掉分割线 1>设置android:divider="@null" 2>android:divider="#0000000 ...
- 软件工程课程作业(一)—20道随机四则运算题(C++)
一.编程思想: 1.定义所需要变量2.设置数组,存储运算符,3.通过随机函数random(0,100)找出运算数,random(0,4)找出运算符4.通过输出显示运算式. 二.源代码: //2016 ...
- 一个方法中的ajax在success中renturn一个值,但是方法的返回值是undefind?
https://segmentfault.com/q/1010000003762379 A页面 console.log(handleData("search_list", &quo ...
- Codeforces Round #125 (Div. 2)
A. Hexadecimal's theorem 三个数没有限制,直接输出\(0\ 0\ n\). B. Special Olympics 分包含和外离情况,包含分2种情况. C. About Bac ...
- URAL 1176 Hyperchannels(欧拉回路路径)
Hyperchannels Time limit: 1.0 secondMemory limit: 64 MB The Galaxy Empire consists of N planets. Hyp ...
- 奇怪的电梯(HDU1548) (Dijkstra)或者(BFS)
问题 E: 奇怪的电梯 时间限制: 1 Sec 内存限制: 64 MB提交: 35 解决: 16[提交][状态][讨论版] 题目描述 有一天桐桐做了一个梦,梦见了一种很奇怪的电梯.大楼的每一层楼都 ...