传送门

题目

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. 三目运算符与if else的运行效率

    两者的效率比较: 当比较次数较少时,效率一样: 当比较次数较多时,发现ifelse的速度更快,应该是其汇编指令更少的原因.   if else的汇编代码如下:     三目运算符代码如下:

  2. 201621123014《Java程序设计》第十周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. 2. 书面作业 本次PTA作业题集异常 1. 常用异常 结合题集题目7-1回答 1.1 自己以前编写的代码中经常出现 ...

  3. 剑指offer--17.第一个只出现一次的字符

    map默认对key进行排序,unordered_map不对键或值进行排序,但是也不是默认插入的顺序 -------------------------------------------------- ...

  4. git教程2-删除修改和文件

    文件处于三种状态: 1.位于工作区,未修改状态: 2.位于工作区,已经修改状态: 3.位于暂存区,已经暂存但未commit. 4.已经commit. 一.文件删除修改: 1.已经修改,但未add: g ...

  5. 修改altibase MDB中的复制表的表结构

    前提条件:有MDB两个数据库,且知道普通用户和sys用户的密码等基本信息.操作:1:用sys用户登录isqlisql -s 127.0.0.1 -u sys -p manager -port 2030 ...

  6. Redis底层探秘(六):对象多态及回收

    本篇是我们redis系列的最后一篇,整个系列其实是我学习<redis设计与实现>的笔记,这本书感觉不错,推荐使用redis的小伙伴都可以看看. 整个系列的文字都比较干,很多数据结构和C语言 ...

  7. Jquery中.ajax和.post详解

    之前写过一篇<.NET MVC 异步提交和返回参数> ,里面有一些ajax的内容,但是不深入,这次详细剖析下jquery中$.ajax的用法. 首先,上代码: jquery-1.5.1 $ ...

  8. Codeforces 786C. Till I Collapse 主席树

    题目大意: 给定一个长度为\(n\)的序列,要求将其划分为最少的若干段使得每段中不同的数字的种数不超过\(k\). 对于 \(k = 1 .. n\)输出所有的答案. \(n \leq 10^5\) ...

  9. 冒泡算法-bubble

    冒泡算法在数据只有几个无序时是最快的算法,但是如果全部无序的话就变成了最慢的算法了,时间复杂度为O(n^2) public class bubbleSort { public static void ...

  10. 使用POI导出excel基础篇

    最近搞了下POI导出Excel,听说很多次,却是第一次搞. 在pom.xml中引入依赖 <dependency> <groupId>org.apache.poi</gro ...