Description

 序列A由从N开始的连续K个数按顺序构成,现在将A中的每个数只保留某一个数码,记为序列B,给定K和B,求可能的最小的N

Input

第一行一个数K,第二行K个数B_i

Output

输出一个数N

当确定了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的更多相关文章

  1. Baltic2014 sequence

    问题描述 输入格式 输出格式 一个整数R 样例输入 7 9 4 8 20 14 15 18 样例输出 13 数据范围 所求的Z序列为6,7,8,13,14,15,18. R=13 解析&左偏树 ...

  2. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  3. oracle SEQUENCE 创建, 修改,删除

    oracle创建序列化: CREATE SEQUENCE seq_itv_collection            INCREMENT BY 1  -- 每次加几个              STA ...

  4. Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等

    功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...

  5. DG gap sequence修复一例

    环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...

  6. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  7. [LeetCode] Sequence Reconstruction 序列重建

    Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...

  8. [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  9. [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 ...

随机推荐

  1. ucsc工具集合

    wget http://hgdownload.cse.ucsc.edu/admin/jksrc.zip 解压后所有工具在kent目录里 发现个更方便的.... http://hgdownload.cs ...

  2. Git简易的命令行入门教程

    简易的命令行入门教程: Git 全局设置: git config --global user.name "imsoft" git config --global user.emai ...

  3. 感知机-Python实现

    如图3所示的训练数据集,其正实例点是(3,3),(3,4),负实例点是(1,1),试用感知机学习算法的原始形式求感知机模型,即求出w和b.这里, 图3 这里我们取初值,取.具体问题解释不写了,求解的方 ...

  4. 作业6 NABCD模型分析,产品Backlog

    1.N(Need 需求): 随着生活水平的提高,每个家庭中都会有电脑和移动设备,可以更加快捷方便使用软件.以前孩子练习计算能力需要通做习题卷或老师出题目来进行,但现在只要通过这个四则运算的程序,可以自 ...

  5. Apache配置日志功能

    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent ...

  6. Codeforces Round #141 (Div. 2)

    A. Is your horseshoe on the other hoof? 模拟题意. B. Two Tables 暴力枚举\(x,y\). C. Fractal Detector 显然,判断图形 ...

  7. rectangle类。java

    import java.util.Scanner; class rectangle{    int l,w;    rectangle(int lon,int wid){    l=lon;    w ...

  8. 【转】ios的控件UIScrollView的位置定位---------逐渐积累

    原文网址:http://blog.csdn.net/z343929897/article/details/8106408 UIScrollView的判断位置的属性如下:   contentSize:C ...

  9. easyUI之Form(表单)组件

    一.对于在easyui中使用的组件,具有输入.输出功能的使用<input>标签,其它的使用<div>标签. 二.对于<input>标签,在使用过程,将name属性和 ...

  10. Entity Framework调用表值函数实现全文检索?

    CREATE FUNCTION [dbo].[udf_BookContentSearch](@keywords NVARCHAR(1000))RETURNS @BookPageDetail TABLE ...