可以YY一下嘛= =

最后一定是-1, -1, ..., -1, 0, 0, ... 0, 1, 1, ..., 1的一个数列

于是f[i][j]表示到了第i个数,新数列的第j项为-1 or 0 or 1的的最小代价

然后就没有然后了

 /**************************************************************
Problem: 3427
User: rausen
Language: C++
Result: Accepted
Time:808 ms
Memory:16432 kb
****************************************************************/ #include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
const int N = ;
const int inf = 1e9; int a[N], f[N][];
int n, ans = inf; inline int read() {
int x = , sgn = ;
char ch = getchar();
while (ch < '' || '' < ch) {
if (ch == '-') sgn = -;
ch = getchar();
}
while ('' <= ch && ch <= '') {
x = x * + ch - '';
ch = getchar();
}
return sgn * x;
} int main() {
int i, j, k;
int t, to;
n = read();
for (i = ; i <= n; ++i)
a[i] = read();
memset(f, , sizeof(f));
f[][a[] + ] = ;
for (i = ; i < n; ++i)
for (j = ; j <= ; ++j) if (f[i][j] < inf)
for (t = j - , k = ; k <= ; ++k) {
to = a[i + ] + k * t;
if (to >= - && to <= && to >= t)
f[i + ][to + ] = min(f[i + ][to + ], f[i][j] + k);
}
for (i = ; i <= ; ++i)
ans = min(ans, f[n][i]);
if (ans == inf) puts("BRAK");
else printf("%d\n", ans);
return ;
}

BZOJ3427 Poi2013 Bytecomputer的更多相关文章

  1. BZOJ3427 Poi2013 Bytecomputer 【dp】

    题目链接 BZOJ3427 题解 容易发现最终序列一定是\(\{-1,0,1\}\)组成的 因为如果有一个位置不是,那么这个位置一定大于\(1\),那么上一个位置一定为\(1\),所以该位置一定加到过 ...

  2. 【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 ...

  3. 【BZOJ】3427: Poi2013 Bytecomputer

    题意: 给定一个长度为\(n\)的\(\{-1, 0, 1\}\)组成的序列,你可以进行\(x_i=x_i+x_{i-1}\)这样的操作,求最少操作次数使其变成不降序列.(\(n \le 100000 ...

  4. bzoj3427:[POI2013]BAJ-Bytecomputer

    传送门 很显然有一个结论:最大不过1,最小不过-1 然后dp,设\(f[i][j]\)为满足前\(i\)个不下降,当前放的是\(j-2\),转移就比较好想了 具体方程看代码吧,终于有一个自己会写的题了 ...

  5. POI2013 Bytecomputer

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3427 可以证明最终序列为-1...0....1 因为首先如果 a(i-1) 为-1或0,执行操 ...

  6. POI2013题解

    POI2013题解 只做了BZ上有的\(13\)道题. 就这样还扔了两道神仙构造和一道计算几何题.所以只剩下十道题了. [BZOJ3414][Poi2013]Inspector 肯定是先二分答案,然后 ...

  7. bzoj AC倒序

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

  8. [POI2013]Łuk triumfalny

    [POI2013]Łuk triumfalny 题目大意: 一棵\(n(n\le3\times10^5)\)个结点的树,一开始\(1\)号结点为黑色.\(A\)与\(B\)进行游戏,每次\(B\)能选 ...

  9. [POI2013]Polaryzacja

    [POI2013]Polaryzacja 题目大意: 给定一棵\(n(n\le250000)\)个点的树,可以对每条边定向成一个有向图,这张有向图的可达点对数为树上有路径从\(u\)到达\(v\)的点 ...

随机推荐

  1. 知乎live 我的读书经验 总结

    https://www.zhihu.com/lives/757587093366009856/messages 碎片化阅读没有意义, 捡硬币捡成富翁 kindle不能全文检索   短篇文章的阅读是否有 ...

  2. 转!!spring @component 详解 默认初始化bean的名字 VNumberTask类 就是 VNumberTask

    参考链接:信息来源 今天碰到一个问题,写了一个@Service的bean,类名大致为:CUser xml配置: <context:component-scan base-package=&quo ...

  3. MonkeyScript使用教程

    原文地址https://www.cnblogs.com/yizhou-xu/p/8072813.html 原文地址https://www.cnblogs.com/YatHo/p/7205162.htm ...

  4. 自定义查询语句SpringData

    虽然官方的API中给我们提供了很多关键字的查询,但是还是不够灵活,因为我们在项目中,会遇见奇葩的业务,我们需要用SpringData中的一个@Query注解. 使用@Query自定义查询 这种查询可以 ...

  5. ZOJ Monthly, June 2018 Solution

    A - Peer Review Water. #include <bits/stdc++.h> using namespace std; int t, n; int main() { sc ...

  6. SQL substring()函数

    ①substring()函数是个截取函数,不同的数据库语法有区别 MySQL: SUBSTR( ), SUBSTRING( ) Oracle: SUBSTR( ) SQL Server: SUBSTR ...

  7. U盘安装window系统

    U盘安装window系统: 1. 制作系统启动U盘,推荐使用老毛桃. 2. 电脑上插入U盘,启动系统,选择U盘启动. 3. 进入老毛桃选择界面,选择生成PE系统.推荐win8,之前在一个戴尔电脑上使用 ...

  8. webpack踩过的坑(总结)

    使用process.argv 获取命令行使用的参数 // 判断是否带production参数,production会压缩js var isprod = false; for (var i in pro ...

  9. Python笔记 #12# Dictionary & Pandas: Object Creation

    Document of Dictionaries 10 Minutes to pandas tutorialspoint import pandas as pd data = [['Alex',10] ...

  10. 《Java程序设计》第三章-基础语法

    20145221<Java程序设计>第三章-基础语法 总结 教材学习内容总结 类型.变量与运算符 类型 Java可区分为基本类型(Primitive Type)和类类型(Class Typ ...