GCJ Round 1C 2009 Problem C. Bribe the Prisoners
区间DP。dp[i][j]表示第i到第j个全部释放最小费用。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int INF=0x7FFFFFFF;
const int maxn=+;
int T,P,Q;
int a[maxn];
int dp[maxn][maxn]; void read()
{
scanf("%d%d",&P,&Q);
for(int i=;i<=Q;i++) scanf("%d",&a[i]);
sort(a+,a++Q);
a[]=; a[Q+]=P+;
} void init()
{
memset(dp,,sizeof dp);
for(int i=;i<=Q;i++) for(int j=i;j<=Q;j++) dp[i][j]=INF;
} void work()
{
for(int i=;i<=Q;i++)
{
for(int j=;j<=Q;j++)
{
int st=j,en=st+i-;
if(en>Q) continue;
if(i==)
{
dp[st][en]=a[st]-a[st-]-+a[st+]-a[st]-;
continue;
} for(int k=st;k<=en;k++)
{
dp[st][en]=min(
dp[st][en],
dp[st][k-]+dp[k+][en]+(a[en+]--a[st-])-
);
}
}
}
printf("%d\n",dp[][Q]);
} int main()
{
// freopen("D:\\test.in","r",stdin);
// freopen("D:\\test.out","w",stdout);
scanf("%d",&T);
for(int Case=;Case<=T;Case++)
{
read();
init();
printf("Case #%d: ",Case);
work();
}
return ;
}
GCJ Round 1C 2009 Problem C. Bribe the Prisoners的更多相关文章
- Google Code Jam Round 1C 2015 Problem A. Brattleship
Problem You're about to play a simplified "battleship" game with your little brother. The ...
- Google Code Jam 2010 Round 1C Problem A. Rope Intranet
Google Code Jam 2010 Round 1C Problem A. Rope Intranet https://code.google.com/codejam/contest/61910 ...
- TCO 2014 Round 1C 概率DP
TCO round 1C的 250 和500 的题目都太脑残了,不说了. TCO round 1C 950 一个棋子,每次等概率的向左向右移动,然后走n步之后,期望cover的区域大小?求cover, ...
- GCJ1C09C - Bribe the Prisoners
GCJ1C09C - Bribe the Prisoners Problem In a kingdom there are prison cells (numbered 1 to P) built t ...
- Google Code Jam 2009, Round 1C C. Bribe the Prisoners (记忆化dp)
Problem In a kingdom there are prison cells (numbered 1 to P) built to form a straight line segment. ...
- Google Code Jam 2010 Round 1C Problem B. Load Testing
https://code.google.com/codejam/contest/619102/dashboard#s=p1&a=1 Problem Now that you have won ...
- GCJ——Crazy Rows (2009 Round 2 A)
题意: 给定一个N*N的矩阵,由0,1组成,只允许交换相邻的两行,把矩阵转化为下三角矩阵(对角线上方全是0),最少需要多少次交换?(保证可以转化为下三角矩阵) Large: N<=40 解析: ...
- Google Code Jam Round 1A 2015 Problem B. Haircut 二分
Problem You are waiting in a long line to get a haircut at a trendy barber shop. The shop has B barb ...
- Kickstart Round D 2017 problem A sightseeing 一道DP
这是现场完整做出来的唯一一道题Orz..而且还调了很久的bug.还是太弱了. Problem When you travel, you like to spend time sightseeing i ...
随机推荐
- Java获取来访者IP
在JSP里,获取客户端的IP地址的方法是:request.getRemoteAddr(),这种方法在大部分情况下都是有效的.但是在通过了Apache,Squid等反向代理软件就不能获取到客户端的真实I ...
- frame、bounds表示大小和位置的属性以及center、position、anchorPosition
在iOS开发开发过程中经常会用到界面元素的frame.bounds表示大小和位置的属性以及center.position.anchorPosition等单纯表示位置的属性.这些属性究竟什么含义?彼此间 ...
- 基于Sublime Text搭建Python IDE
http://loosky.net/2967.html(包括SublimeREPL插件的安装和设置快捷键) SublimeCodeIntel,智能提示功能,查找自定义函数引用的快捷键--Alt+鼠标左 ...
- java socket网络编程(多线程技术)
Client.java import java.io.*; import java.net.*; import java.util.*; public class Client { public st ...
- Safari WebApp 模拟 原声APP禁止打开新窗口JS代码
if(("standalone" in window.navigator) && window.navigator.standalone) { var noddy, ...
- jQuery笔记(1)
jQuery 是一个类库 拥有众多js函数的类库 jQuery 大大简化了js的书写代码,看的舒服,用的爽. jQuery 是一个数组,它能够隐性的遍历. 比如 ${"button" ...
- angular 实现modal windows效果(即模态窗口,半透明的遮罩层),以及bootstrap(css,components,js)的初步学习
废话不说,直接上代码.可直接看效果,对着分析..今天算是bootstrap 入门了,开心.. 突然居然很多事情就是那样,不要太多的畏惧,迈出第一步其实就成功了一半了. <html ng-app= ...
- hibernate 使用sql 查询(setResultTransformer)
使用方法举例如下: public List findByOid(Object oid) { log.debug("finding all WatershedAnalyse instance ...
- 一个门外汉的理解 ~ Faster R-CNN
首先放R-CNN的原理图 显然R-CNN的整过过程大致上划分为四步: 1.输入图片 2.生成候选窗口 3.对局部窗口进行特征提取(CNN) 4.分类(Classify regions) 而R-CNN的 ...
- 解决adb command not found以及sdk环境配置
解决adb command not found以及sdk环境配置 分类: mark 2013-10-02 09:41 2975人阅读 评论(0) 收藏 举报 原文地址:http://www.cnblo ...