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 ...
随机推荐
- /var/lib/mysql/mysql.sock错误的解决办法
问题描述: 使用mysql -uroot -p登录出现找不到 /var/lib/mysql/mysql.sock或者被使用的问题. 可以用如下命令登录:mysql -p --socket=/tmp/m ...
- webservice(soap)接口的加密,SHA-1实现
import java.io.UnsupportedEncodingException;import java.security.MessageDigest;import java.security. ...
- Swift 学习笔记(五)
126. 协议(Protocols) 协议语法(Protocol Syntax) 属性要求(Property Requirements) 方法要求(Method Requirements) Mutat ...
- 网络获取数据的Xml的Pull解析
网络获取的XML的Pull解析 <?xml version="1.0" encoding="utf-8" ?> - <students> ...
- js表单提交,判断文本框,用户名密码是否为空,JS表单检测!
当表单提交时先触发验证的js代码,当验证表单的方法返回true时才会提交表单返回false则不提交数据<script type="text/javascript">fu ...
- CodeForces 689C Mike and Chocolate Thieves (二分最大化最小值)
题目并不难,就是比赛的时候没敢去二分,也算是一个告诫,应该敢于思考…… #include<stdio.h> #include<iostream> using namespace ...
- eclipse,android Localization (Internationalization) 安卓本地化(国际化)
1.创建新的资源文件,名字保持一致.提示"已存在",继续. 2.使用“语言”作为识别器,然后选择相应的语言代码.Tips:其他的适配,如国家.屏幕大小等,也是通过这里的识别器实现适 ...
- 使用过滤器(Filter)解决请求参数中文乱码问题(复杂方式)
前述: 在写这篇笔记之前,对笔记中的设计模式进行介绍: 本篇笔记中将要使用到的设计模式是:装饰(包装)设计模式 (1)装饰(包装)设计模式口诀: ...
- centos minimal Bind 主从服务器部署
实验环境 两台虚拟机BindM和BindS,装的系统都是centos6.3 minimal IP地址 主机名hostname 主DNS服务器 192.168.137.102 bindm.cas.c ...
- 很好的一个dp题目 Codeforces Round #326 (Div. 2) D dp
http://codeforces.com/contest/588/problem/D 感觉吧,这道题让我做,我应该是不会做的... 题目大意:给出n,L,K.表示数组的长度为n,数组b的长度为L,定 ...