Bribe the Prisoners(Easy)
来源:互联网 发布:金蝶引出数据失败原因 编辑:程序博客网 时间:2024/05/17 05:11
Bribe the Prisoners(Easy)
点击链接
思路:区间dp
定义:dp[i][j] 释放a[i],到a[j] 的囚犯( 不包含两端点)所需要的最少金币数。
释放某一个囚犯时:
1.此时所需要的金币数
2.释放左边部分所需要花费的金币数
3.释放右边部分所需要花费的金币数
这三者之和为所需要的金币总数。
区间dp的思路 就是从小区间,递推到大区间。
//// Created by luozujian on 17-10-21.//#include<iostream>#include<cstring>#include<algorithm>#include<cstdio>#include<queue>#include<vector>#define INF 0x3f3f3f3fusing namespace std;const int maxn = 1e2+5;int dp[maxn][maxn]; //释放从i,j所需要的金币。不包含两端int a[maxn];int p,q;int n;int Kase;void solve(){ a[0] = 0; a[q+1] = p + 1; for(int i=0;i<=q;i++) dp[i][i+1] = 0; for(int w = 2;w<=q+1;w++)//区间长度 { for(int i=0;i+w<=q+1;i++)//区间起点 { int j = i+w;int t = INF; for(int k = i+1;k<j;k++) { t = min(t,dp[i][k] + dp[k][j]); } dp[i][j] = t + a[j] - a[i] -2; } } printf("Case #%d: %d\n",++Kase,dp[0][q+1]);}int main(){ Kase = 0; int t; scanf("%d",&t); while(t--) { scanf("%d%d",&p,&q); for(int i=1;i<=q;i++)scanf("%d",&a[i]); solve(); } return 0;}
阅读全文
0 0
- Bribe the Prisoners(Easy)
- GCJ1C09C - Bribe the Prisoners
- SPOJ - GCJ1C09C Bribe the Prisoners
- [Code Jam] Bribe the Prisoners
- GCJ 2009 Bribe the Prisoners
- DP-记忆化dp--Bribe the Prisoners
- ***SPOJ - GCJ1C09C Bribe the Prisoners【贿赂囚犯】
- GCJ 2009 Round1C C Bribe the Prisoners
- 编程题-贿赂囚犯(Bribe the prisoners)-动态规划|剪枝
- 刷题: bribe the prisoners(2009 Round 1C C)
- GCJ 2009 Round 1C C (Bribe the Prisoners)
- GCJ--Bribe the Prisoners (2009 Round 1C C)
- GCJ 2009 Round 1C Bribe the Prisoners
- Code Jam 2009 Round1C Problem C. Bribe the Prisoners —— 区间DP
- Google Code Jam 2009, Round 1C C. Bribe the Prisoners (记忆化dp)
- Bribe the Prisoners——GCJ 2009 Round1C C(区间dp)
- 挑战2.7.3 Round 1C 2009 C. Bribe the Prisoners 区间dp
- 记忆化搜搜——Code Jam 2009 Round 1C #C Bribe the Prisoners
- 【服务器】owncloud的WebDAV
- CSS3 pointer-events:none应用举例及扩展
- 人工智能算法--KNN算法(C++实现)
- 字符串的选择性拷贝
- 在一个有序的旋转数组中,查找给定值
- Bribe the Prisoners(Easy)
- Machine Learning 学习 之 Qleaning 学习
- 基本运算符
- Android--(14)--通过安卓选择器来修改actionbar的样式与字体样式
- sizeof的特点和用法
- c语言之最大数/阶乘求和、加密
- Machine Learning 学习之朴素贝叶斯
- 初学C语言感想。
- test engineer