hdu4283 You Are the One
题目
The TV shows such as You Are the One has been very 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?
The next n line are n integer D1-Dn means the value of diaosi of boys (0 <= Di <= 100)
For each test case, output the least summary of unhappiness .
题目大意
有n个人,输入n个基值(愤怒值)v[],表示每个人的愤怒值,现在他们依次上台表演,如果i是第k个上台,那么他的愤怒值为(k-1)*v[i] 现在有一个栈,可以让一些人进栈,让后面的人先上台表演,这样可以改变部分顺序,求所有人最小的愤怒值和。
分析
用dpij表示i到j区间的人的最小值,我们枚举考虑的区间的长度和起点,并枚举这段区间的第一个人是在第几个登场,注意特判这个人第一个和最后一个登场的情况。为了集体后移时的计算方便,我们记录一个前缀和。具体转移方程等见代码。
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int dp[][],sum[],v[];
int main()
{ int n,m,i,j,k,t,p;
scanf("%d",&t);
for(p=;p<=t;p++){
scanf("%d",&n);
sum[]=;
for(i=;i<=n;i++){
scanf("%d",&v[i]);
sum[i]=sum[i-]+v[i];
dp[i][i]=;
}
for(i=;i<n;i++)
for(j=;j+i<=n;j++){
dp[j][j+i]=min(sum[j+i]-sum[j]+dp[j+][j+i],dp[j+][j+i]+v[j]*i);
for(k=;k<=i;k++)
dp[j][j+i]=min(dp[j][j+i],dp[j+k][j+i]+dp[j+][j+k-]+v[j]*(k-)+(sum[j+i]-sum[j+k-])*k);
}
printf("Case #%d: %d\n",p,dp[][n]);
}
return ;
}
hdu4283 You Are the One的更多相关文章
- HDU4283 You Are the One —— 区间DP
题目链接:https://vjudge.net/problem/HDU-4283 You Are the One Time Limit: 2000/1000 MS (Java/Others) M ...
- hdu4283 区间dp
//Accepted 300 KB 0 ms //区间dp //dp[i][j] 表示i到j第一个出场的最小diaosizhi //对于i到j考虑元素i //(1)i第一个出场,diaosizhi为 ...
- HDU4283:You Are the One(区间DP)
Problem Description The TV shows such as You Are the One has been very popular. In order to meet the ...
- hdu4283(区间dp)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4283 题意:有一个队列,每个人有一个愤怒值D,如果他是第K个上场,不开心指数就为(K-1)*D.但是边 ...
- hdu4283 You Are the One 区间DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4283 自己想了很久还是不会,参考了别人的思路才写的,区间DP还是很弱,继续努力!! 思路: 转载: 题 ...
- HDU4283(KB22-G)
You Are the One Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu-4283 You Are the One 区间dp,
题意:n个人排队上台,每个人有一屌丝值D,他的不满意值=D*(k-1)(k为他前面的总人数). 求整个队列不满意值之和的最小值.你只有一个操作,就是把队首的人塞进小黑屋,也就是压入栈中,后面的人就被提 ...
- 刷题总结——you are the one(hdu4283)
题目: The TV shows such as You Are the One has been very popular. In order to meet the need of boys wh ...
- hdu4283
You Are the One Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- OOP思想应该怎样来理解?
https://blog.csdn.net/qq157962718/article/details/50990154 https://www.cnblogs.com/xiaosongluffy/p/5 ...
- HTTP协议 与 Requests库
HTTP协议 与 Requests库: 1 HTTP协议: 2 URL作为网络定位的标识: >>>> 用户通过url来定位资源 >>>> 然后通过 g ...
- linux shell 学习笔记--文件测试符
. 文件测试操作 ---------------- 返回true 如果... -e 文件存在 -a 文件存在 这个选项的效果与-e 相同.但是它已经被弃用了,并且不鼓励使用 -f file 是一个re ...
- Rational Rose 2003 下载、破解及安装方法(图文)
方法一: 1. 安装Rational Rose2003时,在需选择安装项的时候,只选择Rational Rose EnterPrise Edition即可,不需选择其他项,之后选择“DeskTop I ...
- qq群文件管理
一.怎样登录QQ群空间查看.管理群文件 1)登录自己的QQ,打开主面板!小编在这里以访问自己的群“我们的六班”为例.2)鼠标移动到主面板中“我们的六班”群图标处,右建单击——选择“访问QQ群空间”—— ...
- Weblogic-unable to get file lock, will retry …问题解决
weblogic部署应用出现如下报错: <2017-8-15 下午05时08分44秒 CST> <Info> <Management> <BEA-141281 ...
- Visualforce入门第六篇_2017.3.1
Visualforce实现过滤.数据列表显示.分页功能 可以参考salesforce官网开发文档:https://trailhead.salesforce.com/modules/visualforc ...
- java中final用法
1.修饰基础数据成员 这是final的主要用途,其含义相当于C/C++的const,即该成员被修饰成常量,不可修改. 2.修饰类或者对象的引用的final 在java中我们无法让对象被修饰为final ...
- maven工程编译成jar包
在pom文件的project节点下增加build节点,mvn package即可 <build> <plugins> <plugin> <artifactId ...
- Angular5学习笔记 - 服务优化(十)
一.服务合并 二.验证效果