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 ...
随机推荐
- 关于typedef的用法总结(转)
不管实在C还是C++代码中,typedef这个词都不少见,当然出现频率较高的还是在C代码中.typedef与#define有些相似,但更多的是不同,特别是在一些复杂的用法上,就完全不同了,看了网上一些 ...
- iOS学习笔记---c语言第十一天
函数指针 一.函数指针定义 //函数声明:声明我是一个什么函数 //求两个数的和 //函数的类型:int (int x,int y) //即:我是一个返回值为整型,有两个整型参数的函数. //函数名是 ...
- WebRTC录音(2)-录音文件转换成WAV格式
以下是源码,大路货,从网上找的. 但是,这个东西在MacOS上是有问题的,原因在最后,都是泪啊. #include <stdio.h> #include <string.h> ...
- Matlab神经网络工具箱学习之一
1.神经网络设计的流程 2.神经网络设计四个层次 3.神经网络模型 4.神经网络结构 5.创建神经网络对象 6.配置神经网络的输入输出 7.理解神经网络工具箱的数据结构 8.神经网络训练 1.神经网络 ...
- c++函数重载---2
原创博客:转载请标明出处:http://www.cnblogs.com/zxouxuewei/ 写在前面: 函数重载的重要性不言而明,但是你知道C++中函数重载是如何实现的呢(虽然本文谈的是C++中函 ...
- Objective-c——UI基础开发第六天(UITableView)
一.UITableView的简单使用 显示要素: 1.显示多少给区组 2.显示多少行数据 3.每行显示什么内容 代理不会提醒你有什么方法没调用,但是UITableViewDataSource会 1)用 ...
- CentOS配置LAMP环境
环境:CentOS 6.5 配置防火墙,开启80端口.3306端口 # Firewall configuration written by system-config-firewall # Manua ...
- (转) A Survival Guide to a PhD
A Survival Guide to a PhD Sep 7, 2016 This guide is patterned after my “Doing well in your courses”, ...
- Spark 优化器 ML的论文
http://people.csail.mit.edu/matei/papers/2015/sigmod_spark_sql.pdf http://www.vldb.org/pvldb/vol4/p5 ...
- C#加载dll 创建类对象
//加载dll 创建类对象string sqlightAssembly = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "syst ...