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. jQuery关于Select的操作

    jQuery获取Select选择的Text和Value: 1. var checkText=jQuery("#select_id").find("option:selec ...

  2. [转载] Python 列表(list)、字典(dict)、字符串(string)常用基本操作小结

    创建列表 sample_list = ['a',1,('a','b')] Python 列表操作 sample_list = ['a','b',0,1,3] 得到列表中的某一个值 value_star ...

  3. HDU 4311 前缀和

    Description It has been ten years since TJU-ACM established. And in this year all the retired TJU-AC ...

  4. C++ Primer : 第十章 : 泛型算法 之 lambda表达式和bind函数

    一.lambda表达式 lambda表达式原型: [capture list] (parameter list) -> retrue type { function body } 一个lambd ...

  5. tools/version.c

    /* *  linux/version.c * *  Copyright (C) 1992  Theodore Ts'o * *  May be freely distributed as part ...

  6. 数据库实验一 SQL Service的安装

    SQL 2014 安装需要 Microsoft .Net Framework 3.5框架 win 8.1 Microsoft .Net Framework 3.5框架安装教程:点我 安装图文教程:点我 ...

  7. Linux 安装rar解压工具

    下载RAR安装包: http://www.rarsoft.com/download.htm 我的是CentOS 64位: wget http://www.rarsoft.com/rar/rarlinu ...

  8. MySQL root密码重置 报错:mysqladmin: connect to server at 'localhost' failed的解决方案

    ===========================================================二,忘记本地root的登录密码解决过程:1.编辑/mysql/my.ini在[my ...

  9. breakpoints

    https://blogs.msdn.microsoft.com/visualstudioalm/2013/10/07/breakpoints-in-visual-studio-2013/ Using ...

  10. background-position 用法详细介绍

    语法: background-position : length || length background-position : position || position 取值: length  : ...