BZOJ3427 Poi2013 Bytecomputer
2024-10-07 15:19:45
可以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 ;
}
最新文章
- Hadoop技巧系列索引
- Jexus 支持PHP的三种方式
- Android studio 中的配置编译错误总结
- Oracle笔记3-高级查询
- GPUImage 内置滤镜解析
- php文件格式数组
- WordPress插件制作教程(二): 编写一个简单的插件
- HDU 4009 Transfer water
- WebForm 全局对象、commend
- leetcode算法题(JavaScript实现)
- Python-模块使用-Day6
- Spring Security入门(3-7)Spring Security处理页面的ajax请求
- mysql 开发进阶篇系列 12 锁问题(隔离级别下锁的差异)
- micro-template改造
- ElasticSearch入门 第二篇:集群配置
- 20165236 《Java程序设计》第七周学习总结
- 使用CSDN-markdown编辑器
- Python Flask 构建微电影视频网站
- MAC下安装Brew[转]
- 浏览器本地存储(browser-storage)
热门文章
- ";errmsg"; : ";distinct too big, 16mb cap";,
- CMDB经验分享之 – 剖析CMDB的设计过程
- 洛谷P1373 小a和uim之大逃离 dp
- Elasticsearch入门教程
- 史上最全的MonkeyRunner自动化测试从入门到精通(2)
- js中 a : function(){}这是什么格式? 代表什么含义?怎样学习这样的格式?
- bzoj1602 / P2912 [USACO08OCT]牧场散步Pasture Walking(倍增lca)
- Eclipse配置tomcat8.5.7报错:The Apache Tomcat installation at this directory is version 8.5.27. A Tomcat 8.0 installation is...
- linux中readl()和writel()函数---用于读写寄存器
- git clone时提示(gnome-ssh-askpass:29288): Gtk-WARNING **: cannot open display: