传送门

题目

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?

Input
The first line contains a single integer T, the 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)
Output

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的更多相关文章

  1. HDU4283 You Are the One —— 区间DP

    题目链接:https://vjudge.net/problem/HDU-4283 You Are the One Time Limit: 2000/1000 MS (Java/Others)    M ...

  2. hdu4283 区间dp

    //Accepted 300 KB 0 ms //区间dp //dp[i][j] 表示i到j第一个出场的最小diaosizhi //对于i到j考虑元素i //(1)i第一个出场,diaosizhi为 ...

  3. 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 ...

  4. hdu4283(区间dp)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4283 题意:有一个队列,每个人有一个愤怒值D,如果他是第K个上场,不开心指数就为(K-1)*D.但是边 ...

  5. hdu4283 You Are the One 区间DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4283 自己想了很久还是不会,参考了别人的思路才写的,区间DP还是很弱,继续努力!! 思路: 转载: 题 ...

  6. HDU4283(KB22-G)

    You Are the One Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  7. hdu-4283 You Are the One 区间dp,

    题意:n个人排队上台,每个人有一屌丝值D,他的不满意值=D*(k-1)(k为他前面的总人数). 求整个队列不满意值之和的最小值.你只有一个操作,就是把队首的人塞进小黑屋,也就是压入栈中,后面的人就被提 ...

  8. 刷题总结——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 ...

  9. hdu4283

    You Are the One Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

随机推荐

  1. spring学习-4

    bean的作用域 使用bean的scope属性来配置bean的作用域 scope="singleton":默认是单例模式即容器初始化创建bean实例,在整个容器的生命周期内只创建这 ...

  2. pthread_getspecific()--读线程私有数据|pthread_setspecific()--写线程私有数据

    原型: #include <pthread.h> void *pthread_getspecific(pthread_key_t key); int pthread_setspecific ...

  3. RTP协议全解(H264码流和PS流)

    写在前面:RTP的解析,网上找了很多资料,但是都不全,所以我力图整理出一个比较全面的解析, 其中借鉴了很多文章,我都列在了文章最后,在此表示感谢. 互联网的发展离不开大家的无私奉献,我决定从我做起,希 ...

  4. CodeForces - 961D:Pair Of Lines (几何,问两条直线是否可以覆盖所有点)

    You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordin ...

  5. Python+Apache+CGI完全配置

    http://www.tuicool.com/articles/jIZfaqQ 操作系统环境:Ubuntu 15.10 0.需求原因 想在我的Linux上架设Apache来运行CGI程序,方便以后用A ...

  6. 异常:java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlType

    这个是jdK版本的问题的. 本地编译的jar包是1.8的,但是跑jar包的环境jdk版本是1.9的. 升级1.9之后由于jdk当方面的取消了几个jar,所以导致编译起不来. 明天研究一下如何添加jar ...

  7. Java-API-POI-Excel:SXSSFWorkbook Documentation

    ylbtech-Java-API-POI-Excel:SXSSFWorkbook Documentation 1.返回顶部 1. org.apache.poi.xssf.streaming Class ...

  8. throw和throws的区别和联系

    突然发现今天诗兴大发,看来又得写点内容了. throw和throws对于Java程序员而言它们真的不是很陌生.但对于我这样的选手而言一提到它们的区别和联系就蒙圈了... 为了以后不蒙圈,今天就研究一下 ...

  9. web 应用 及 补充

    Highcharts 绘图配置 的函数及参数 web页面文本框修饰器 --- KindEditor web页面 之 超人性的点赞与狂踩 web页面 之 图片上传 web页面 之 评论盖楼 jQuery ...

  10. Ubuntu 下 ROS Kinetic 的安装

    安装环境为 Ubuntu 16.04 配置 Ubuntu 软件仓库 打开“设置”中的“软件和更新” 把 “restricted”.“universe” 和 “multiverse” 这三项勾上 勾完后 ...