GCJ 2009 Bribe the Prisoners
来源:互联网 发布:忘记windows登陆密码 编辑:程序博客网 时间:2024/05/22 04:40
区间DP……但是细节处理比较多,代码要一些技巧……算水题吧
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <vector>#include <cmath>#include <vector>using namespace std;#define LL long longvoid nextInt(int &x){scanf("%d", &x);}void nextInt(int &x, int &y){scanf("%d%d", &x, &y);}const LL maxn = 500;int n;int p;int a[maxn];int f[maxn][maxn];void init(){nextInt(n, p);for (int i = 1; i <= p; ++ i)nextInt(a[i]);a[0] = 0;a[p + 1] = n + 1;sort(a, a + 2 + p);//for (int i = 0; i <= p + 1; ++ i)cout<<a[i]<<endl;memset(f, 0, sizeof(f));for (int w = 2; w <= p + 1; ++ w)//长度for (int i = 0; w + i <= p + 1; ++ i)//开始位置{//(i, i + w)区间, 实际可用区间为[i + 1, i + w - 1]f[i][i + w] = a[w + i] - a[i] - 2;int tmp = 0x7fffffff;for (int k = i + 1; k <= i + w - 1; ++ k){tmp = min(tmp, f[i][k] + f[k][i + w]);}f[i][i + w] += tmp;}printf("%d\n", f[0][p + 1]);}int main(){freopen("a.in","r",stdin);freopen("a.txt","w",stdout);LL sb;scanf("%lld", &sb);for (int i = 1; i <= sb; ++ i){printf("Case #%d: ", i);init();}return 0;}
0 0
- GCJ 2009 Bribe the Prisoners
- GCJ 2009 Round1C C Bribe the Prisoners
- GCJ 2009 Round 1C C (Bribe the Prisoners)
- GCJ--Bribe the Prisoners (2009 Round 1C C)
- GCJ 2009 Round 1C Bribe the Prisoners
- Bribe the Prisoners——GCJ 2009 Round1C C(区间dp)
- Bribe the Prisoners(GCJ 2009 Round 1C C)(dp)
- GCJ1C09C - Bribe the Prisoners
- Bribe the Prisoners(Easy)
- SPOJ - GCJ1C09C Bribe the Prisoners
- [Code Jam] Bribe the Prisoners
- 刷题: bribe the prisoners(2009 Round 1C C)
- DP-记忆化dp--Bribe the Prisoners
- ***SPOJ - GCJ1C09C Bribe the Prisoners【贿赂囚犯】
- Code Jam 2009 Round1C Problem C. Bribe the Prisoners —— 区间DP
- Google Code Jam 2009, Round 1C C. Bribe the Prisoners (记忆化dp)
- 挑战2.7.3 Round 1C 2009 C. Bribe the Prisoners 区间dp
- 记忆化搜搜——Code Jam 2009 Round 1C #C Bribe the Prisoners
- 第七章 virtual模块解析
- 数字格式化 千位符 两位小数
- hdu1029(基础)
- MySQL命令行下执行.sql脚本
- Linux学习之CentOS--虚拟机下的CentOS如何上网
- GCJ 2009 Bribe the Prisoners
- Linux 下I/O多路复用总结
- iOS项目中安装和使用 Cocoapods
- 【笔记】 《js权威指南》- 第15章 脚本化文档 - 15.8 元素的几何形状和滚动
- Object C学习笔记16-委托(delegate)
- 7.1 virtual模块的函数调用关系
- IOS-事务在数据库中的用处
- Linux下线程的调度策略与优先级
- php函数