BZOJ3427 Poi2013 Bytecomputer
可以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的更多相关文章
- BZOJ3427 Poi2013 Bytecomputer 【dp】
题目链接 BZOJ3427 题解 容易发现最终序列一定是\(\{-1,0,1\}\)组成的 因为如果有一个位置不是,那么这个位置一定大于\(1\),那么上一个位置一定为\(1\),所以该位置一定加到过 ...
- 【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]BAJ-Bytecomputer
传送门 很显然有一个结论:最大不过1,最小不过-1 然后dp,设\(f[i][j]\)为满足前\(i\)个不下降,当前放的是\(j-2\),转移就比较好想了 具体方程看代码吧,终于有一个自己会写的题了 ...
- POI2013 Bytecomputer
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3427 可以证明最终序列为-1...0....1 因为首先如果 a(i-1) 为-1或0,执行操 ...
- 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\)的点 ...
随机推荐
- 如何修改git分支名名称
1. 修改本地git分支名称指令 git branch -m oldBranchName newBranchName 2. 修改远程仓库(github)上的分支名称 git本地分支名已修改,只需推送到 ...
- 转载:Why using Single Root I/O Virtualization (SR-IOV) can help improve I/O performance and Reduce Costs
Introduction While server virtualization is being widely deployed in an effort to reduce costs and o ...
- linux 安装 mysql-5.6.26
linux安装mysql-5.6.26 查看工具:winscp 下载地址 http://mirrors.sohu.com/mysql/MySQL-5.6/ 文件: mysql-5.6.26-linux ...
- Spark Shuffle(一)ShuffleWrite:Executor如何将Shuffle的结果进行归并写到数据文件中去(转载)
转载自:https://blog.csdn.net/raintungli/article/details/70807376 当Executor进行reduce运算的时候,生成运算结果的临时Shuffl ...
- 5makefile
makefile编译多个可执行文件1: 多个 C 文件编译成不同的目标文件2: 多个 C 文件编译成 一个目标文件 注意:makefile的文件名的三种形式(优先级排序)makefile>Mak ...
- Codeforces Round #513 by Barcelona Bootcamp
A. Phone Numbers 签. #include <bits/stdc++.h> using namespace std; #define N 110 char s[N]; ], ...
- IDFA踩坑记录
IDFA踩坑记录: 1.iOS10.0 以下,即使打开“限制广告跟踪”,依然可以读取idfa: 2.打开“限制广告跟踪”,然后再关闭“限制广告跟踪”,idfa会改变: 3.越狱机器安装开发证书打的包, ...
- mongo增删改查封装(C#)
Framework版本:.Net Framework 4 ConnectionUtil源码参见:https://www.cnblogs.com/threadj/p/10536273.html usin ...
- Java笔记 #01# 最近遇到的几个Throwable
续<Java入门第三季>第一章 异常与异常处理. 1.StackOverflowError 第一次碰到这个 Error 居然有点小激动,原因当然是因为它叫 StackOverflow Q: ...
- Java实现文件上传到服务器(FTP方式)
Java实现文件上传到服务器(FTP方式) 1,jar包:commons-net-3.3.jar 2,实现代码: //FTP传输到数据库服务器 private boolean uploadServer ...