可以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 ;
}

最新文章

  1. Hadoop技巧系列索引
  2. Jexus 支持PHP的三种方式
  3. Android studio 中的配置编译错误总结
  4. Oracle笔记3-高级查询
  5. GPUImage 内置滤镜解析
  6. php文件格式数组
  7. WordPress插件制作教程(二): 编写一个简单的插件
  8. HDU 4009 Transfer water
  9. WebForm 全局对象、commend
  10. leetcode算法题(JavaScript实现)
  11. Python-模块使用-Day6
  12. Spring Security入门(3-7)Spring Security处理页面的ajax请求
  13. mysql 开发进阶篇系列 12 锁问题(隔离级别下锁的差异)
  14. micro-template改造
  15. ElasticSearch入门 第二篇:集群配置
  16. 20165236 《Java程序设计》第七周学习总结
  17. 使用CSDN-markdown编辑器
  18. Python Flask 构建微电影视频网站
  19. MAC下安装Brew[转]
  20. 浏览器本地存储(browser-storage)

热门文章

  1. &quot;errmsg&quot; : &quot;distinct too big, 16mb cap&quot;,
  2. CMDB经验分享之 – 剖析CMDB的设计过程
  3. 洛谷P1373 小a和uim之大逃离 dp
  4. Elasticsearch入门教程
  5. 史上最全的MonkeyRunner自动化测试从入门到精通(2)
  6. js中 a : function(){}这是什么格式? 代表什么含义?怎样学习这样的格式?
  7. bzoj1602 / P2912 [USACO08OCT]牧场散步Pasture Walking(倍增lca)
  8. Eclipse配置tomcat8.5.7报错:The Apache Tomcat installation at this directory is version 8.5.27. A Tomcat 8.0 installation is...
  9. linux中readl()和writel()函数---用于读写寄存器
  10. git clone时提示(gnome-ssh-askpass:29288): Gtk-WARNING **: cannot open display: