POI2013 Bytecomputer
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3427
可以证明最终序列为-1...0....1
因为首先如果 a(i-1) 为-1或0,执行操作不会让答案变优。
然后,如果可以加到大于1的某个数字,一定可以加到1,显然加到1更佳。
然后简单dp,f[i][j]表示第i位为j的最少步数。
#include <cstdio>
#include <cstring>
#include <algorithm> #define N 1000010 using namespace std; int f[N][],n,a[N]; int min(int a,int b,int c,int d){
return min(min(a,d),min(b,c));
} int min(int a,int b,int c){
return min(a,min(b,c));
} int calc(int x,int to,int v){
v--;
if(x==to) return ;
if(x+v==to) return ;
if(x+*v==to) return ;
return 0x3f3f3f3f;
} int main(){
memset(f,0x3f,sizeof(f));
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&a[i]),a[i]++;
f[][a[]]=;
for(int i=,s1,s2;i<=n;i++){
f[i][]=min(f[i][],f[i-][]+calc(a[i],,));
f[i][]=min(f[i][],f[i-][]+calc(a[i],,),f[i-][]+calc(a[i],,));
f[i][]=min(f[i][],f[i-][]+calc(a[i],,),f[i-][]+calc(a[i],,),f[i-][]+calc(a[i],,));
}
int ans=min(f[n][],f[n][],f[n][]);
if(ans>=0x3f3f3f3f) puts("BRAK");
else printf("%d\n",ans);
return ;
}
POI2013 Bytecomputer的更多相关文章
- 【bzoj3427】Poi2013 Bytecomputer dp
题目描述 A sequence of N integers I1,I2…In from the set {-1,0,1} is given. The bytecomputer is a device ...
- 【BZOJ】3427: Poi2013 Bytecomputer
题意: 给定一个长度为\(n\)的\(\{-1, 0, 1\}\)组成的序列,你可以进行\(x_i=x_i+x_{i-1}\)这样的操作,求最少操作次数使其变成不降序列.(\(n \le 100000 ...
- BZOJ3427 Poi2013 Bytecomputer
可以YY一下嘛= = 最后一定是-1, -1, ..., -1, 0, 0, ... 0, 1, 1, ..., 1的一个数列 于是f[i][j]表示到了第i个数,新数列的第j项为-1 or 0 or ...
- BZOJ3427 Poi2013 Bytecomputer 【dp】
题目链接 BZOJ3427 题解 容易发现最终序列一定是\(\{-1,0,1\}\)组成的 因为如果有一个位置不是,那么这个位置一定大于\(1\),那么上一个位置一定为\(1\),所以该位置一定加到过 ...
- POI2013题解
POI2013题解 只做了BZ上有的\(13\)道题. 就这样还扔了两道神仙构造和一道计算几何题.所以只剩下十道题了. [BZOJ3414][Poi2013]Inspector 肯定是先二分答案,然后 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- [POI2013]Łuk triumfalny
[POI2013]Łuk triumfalny 题目大意: 一棵\(n(n\le3\times10^5)\)个结点的树,一开始\(1\)号结点为黑色.\(A\)与\(B\)进行游戏,每次\(B\)能选 ...
- [POI2013]Polaryzacja
[POI2013]Polaryzacja 题目大意: 给定一棵\(n(n\le250000)\)个点的树,可以对每条边定向成一个有向图,这张有向图的可达点对数为树上有路径从\(u\)到达\(v\)的点 ...
- [POI2013]Taksówki
[POI2013]Taksówki 题目大意: ABC三地在同一条直线上,AC相距\(m(m\le10^{18})\)米,AB相距\(d\),B在AC之间.总共有\(n(n\le5\times10^5 ...
随机推荐
- gdb源码安装过程中的问题:no termcap library found
gdb使用源码安装的时候遇到错误:no termcap library found ./configure --> make --> make install 解决办法,下载termca ...
- pycharm整体缩进的快捷键
选中多行,按tab进行缩进,按tab+shift去除缩进
- centos 7 安装官方LAMP(Apache+PHP5+MySQL)
启用Apache2 yum install httpd systemctl start httpd.service systemctl status httpd systemctl enable ht ...
- HDU 2825 Wireless Password (AC自己主动机,DP)
pid=2825">http://acm.hdu.edu.cn/showproblem.php? pid=2825 Wireless Password Time Limit: 2000 ...
- DW 表格与表单
CSS样式表
- register_shutdown_function函数详解
设定错误和异常处理三函数 register_shutdown_function(array(‘Debug’,'fatalError’)); //定义PHP程序执行完成后执行的函数 set_error_ ...
- HDU 5274 Dylans loves tree(LCA+dfs时间戳+成段更新 OR 树链剖分+单点更新)
Problem Description Dylans is given a tree with N nodes. All nodes have a value A[i].Nodes on tree i ...
- SDOI2016R1(不是解题报告)
话说洗澡的时候想了一堆要说的,坐到电脑前反而不知所措了-- 序章 听学长说他们都是省选一周前才停的课.然而我们这届--自聪哥韩大他们在省选两周前悄悄跑路后(据说班主任非常支持),信息小组内部一呼百应, ...
- Fairy Tail - Main Theme Slow Version guitar (solo)
Хвост Феи animelodies1 (on youtube) Переписал jarrro (on vk.com)
- xcode4中build Settings常见参数解析
本文转载至 http://shiminghua234.blog.163.com/blog/static/263912422012411103526386/ 1.Installation Dir ...