you are the one(区间dp)
传送门
You Are the One
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4042 Accepted Submission(s):
1876
popular. In order to meet the need of boys who are still single, TJUT hold the
show itself. The show is hold in the Small hall, so it attract a lot of boys and
girls. Now there are n boys enrolling in. At the beginning, the n boys stand in
a row and go to the stage one by one. However, the director suddenly knows that
very boy has a value of diaosi D, if the boy is k-th one go to the stage, the
unhappiness of him will be (k-1)*D, because he has to wait for (k-1) people.
Luckily, there is a dark room in the Small hall, so the director can put the boy
into the dark room temporarily and let the boys behind his go to stage before
him. For the dark room is very narrow, the boy who first get into dark room has
to leave last. The director wants to change the order of boys by the dark room,
so the summary of unhappiness will be least. Can you help him?
number of test cases. For each case, the first line is n (0 < n <=
100)
The next n line are n integer D1-Dn means the value of diaosi of boys
(0 <= Di <= 100)
unhappiness .
5
1
2
3
4
5
5
5
4
3
2
2
Case #2: 24
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define inf 0x7fffffff
int n,t,kas;
int sum[],v[][],dp[][],a[];
void befr() {
for(int i=; i<=n; i++)
for(int j=i-; j>=; j--)
v[j][i]=v[j+][i]+a[j]*(i-j);
}
int main() {
scanf("%d",&t);
while(t--) {
memset(sum,,sizeof(sum));
memset(v,,sizeof(v));
scanf("%d",&n);
for(int i=; i<=n; i++) {
scanf("%d",&a[i]);
sum[i]=sum[i-]+a[i];
}
for(int i=; i<=n; i++)
for(int j=; j<=n; j++)
if(i!=j)
dp[i][j]=inf;
else
dp[i][j]=;
befr();
for(int j=; j<=n; j++)
for(int i=j-; i>=; i--)
for(int k=i; k<j; k++) {
dp[i][j]=min(dp[i][j],min(dp[i][k]+dp[k+][j]+(sum[j]-sum[k])*(k-i+),dp[k+][j]+v[i][k]+(sum[k]-sum[i-])*(j-k)));
}
printf("Case #%d: %d\n",++kas, dp[][n]);
}
return ;
}
you are the one(区间dp)的更多相关文章
- 【BZOJ-4380】Myjnie 区间DP
4380: [POI2015]Myjnie Time Limit: 40 Sec Memory Limit: 256 MBSec Special JudgeSubmit: 162 Solved: ...
- 【POJ-1390】Blocks 区间DP
Blocks Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5252 Accepted: 2165 Descriptio ...
- 区间DP LightOJ 1422 Halloween Costumes
http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...
- BZOJ1055: [HAOI2008]玩具取名[区间DP]
1055: [HAOI2008]玩具取名 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1588 Solved: 925[Submit][Statu ...
- poj2955 Brackets (区间dp)
题目链接:http://poj.org/problem?id=2955 题意:给定字符串 求括号匹配最多时的子串长度. 区间dp,状态转移方程: dp[i][j]=max ( dp[i][j] , 2 ...
- HDU5900 QSC and Master(区间DP + 最小费用最大流)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5900 Description Every school has some legends, ...
- BZOJ 1260&UVa 4394 区间DP
题意: 给一段字符串成段染色,问染成目标串最少次数. SOL: 区间DP... DP[i][j]表示从i染到j最小代价 转移:dp[i][j]=min(dp[i][j],dp[i+1][k]+dp[k ...
- 区间dp总结篇
前言:这两天没有写什么题目,把前两周做的有些意思的背包题和最长递增.公共子序列写了个总结.反过去写总结,总能让自己有一番收获......就区间dp来说,一开始我完全不明白它是怎么应用的,甚至于看解题报 ...
- Uva 10891 经典博弈区间DP
经典博弈区间DP 题目链接:https://uva.onlinejudge.org/external/108/p10891.pdf 题意: 给定n个数字,A和B可以从这串数字的两端任意选数字,一次只能 ...
- 2016 年沈阳网络赛---QSC and Master(区间DP)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5900 Problem Description Every school has some legend ...
随机推荐
- Codeforces 837D Round Subset(背包)
题目链接 Round Subset 题意 在n个数中选择k个数,求这k个数乘积末尾0个数的最大值. 首先我们预处理出每个数5的因子个数c[i]和2的因子个数d[i] 然后就可以背包了. 设f[i] ...
- I.Tower Defense
给你p个重塔,q个轻塔,把这些塔放在n*m的图中,这些塔会相互攻击同行同列的,轻塔不能受到攻击,重塔能承受一个塔的攻击, 问放的方法数. 先假定n < m. 可以先枚举放轻塔的个数为s,显然,方 ...
- python 获取时间 存入文件
1读文件: file_path_name = '/home/robot/bzrobot_ws/src/bzrobot/bzrobot_comm/led_show_data/'+file_name+'. ...
- TOT 傅立叶变换 FFT 入门
HDU 1402,计算很大的两个数相乘. FFT 只要78ms,这里: 一些FFT 入门资料:http://wenku.baidu.com/view/8bfb0bd476a20029bd642d85. ...
- Object源码
1.Object是所有类的父类,默认会继承Object. 2.Object类中常用的方法有:getClass().hashCode().equals().clone().toString().fina ...
- Linux下运行Java项目时,出现No X11 DISPLAY variable was set, but this program performed an operation which requires it.的问题解决
在~/.bashrc环境变量文件最下方加入: export DISPLAY=:0.0 然后,刷新环境变量以使其生效: source -/.bashrc 参考:http://stackoverflow. ...
- 校园网、教育网 如何纯粹访问 IPv6 网站避免收费
我国校园网有可靠的 IPv6 网络环境,速度非常快.稳定,并且大多数高校在网络流量计费时不会限制 IPv6 的流量,也就是免费的.然而访问 IPv4 商业网络时,则会收费,并且连接的可靠性一般.可幸的 ...
- git 更新远程分支
使用git的时候,有时候会出现远端更新了一个分支,但是从本地想checkout一个远程分支时,会出现如下错误: fatal: git checkout: updating paths is incom ...
- C语言枚举类型(Enum)
在实际编程中,有些数据的取值往往是有限的,只能是非常少量的整数,并且最好为每个值都取一个名字,以方便在后续代码中使用,比如一个星期只有七天,一年只有十二个月,一个班每周有六门课程等. 以每周七天为例, ...
- 简谈Java的join()方法(转)
join()是Thread类的一个方法.根据jdk文档的定义: public final void join()throws InterruptedException: Waits for this ...