题目链接

http://acm.split.hdu.edu.cn/showproblem.php?pid=4283

Problem Description
  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 .
 
Sample Input
2
  
5
1
2
3
4
5
5
5
4
3
2
2
 
Sample Output
Case #1: 20
Case #2: 24
 
Source
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  4267 4268 4269 4270 4271 
 
题意:有n个人,输入n个基值(愤怒值)v[],表示每个人的愤怒值,现在他们依次上台表演,如果i是第k个上台,那么他的愤怒值为(k-1)*v[i]  现在有一个栈,可以让一些人进栈,让后面的人先上台表演,这样可以改变部分顺序,求所有人最小的愤怒值和;
 
思路:区间DP,定义dp[i][j]表示原序列中i到j的人的最小愤怒值的和,设i在区间i到j中第k个上场,那么i+1~i+k-1会先i上台,然后i上台,最后i+k~i+len上台,那么状态转移方程为: dp[i][j]=v[i]*(k-1)+dp[i+1][i+k-1]+(sum[i+len]-sum[i+k-1])*k+dp[i+k][i+len]  sum[]表示前缀和;
 
代码如下:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
const int inf=0x7fffffff;
int v[];
int dp[][];
int sum[]; int main()
{
int T,n,Case=;
cin>>T;
while(T--)
{
scanf("%d",&n);
sum[]=;
for(int i=;i<=n;i++)
{
scanf("%d",&v[i]);
sum[i]=sum[i-]+v[i];
}
for(int i=;i<=n;i++)
dp[i][i]=;
for(int len=;len<n;len++)
{
for(int i=;i+len<=n;i++)
{ ///特判i在i~i+len的区间中是第一个和最后一个时的情况;
dp[i][i+len]=min(sum[i+len]-sum[i]+dp[i+][i+len],dp[i+][i+len]+v[i]*len);
for(int k=;k<=len;k++)
dp[i][i+len]=min(dp[i][i+len],v[i]*(k-)+dp[i+][i+k-]+(sum[i+len]-sum[i+k-])*k+dp[i+k][i+len]);
}
}
printf("Case #%d: %d\n",Case++,dp[][n]);
}
}

HDU 4283---You Are the One(区间DP)的更多相关文章

  1. hdu 4283"You Are the One"(区间DP)

    传送门 https://www.cnblogs.com/violet-acmer/p/9852294.html 题意: 有n个屌丝排成一排,每个屌丝都有一个不开心值a[ i ]( i=1,2,3,.. ...

  2. HDU 4283 You Are the One ——区间dp

    参考了许多大佬  尤其是https://blog.csdn.net/woshi250hua/article/details/7973824这一篇 ,最后我再加一点我的见解. 大意是 给定一个序列,序列 ...

  3. hdu 4283 You Are the One 区间dp

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

  4. HDU 4283 (第k个出场 区间DP)

    http://blog.csdn.net/acm_cxlove/article/details/7964594 http://www.tuicool.com/articles/jyaQ7n http: ...

  5. HDU 5900 QSC and Master (区间DP)

    题目链接   http://acm.hdu.edu.cn/showproblem.php?pid=5900 题意:给出序列$A_{i}.key$和$A_{i}.value$,若当前相邻的两个数$A_{ ...

  6. HDU 5115 (杀狼,区间DP)

    题意:你是一个战士现在面对,一群狼,每只狼都有一定的主动攻击力和附带攻击力.你杀死一只狼.你会受到这只狼的(主动攻击力+旁边两只狼的附带攻击力)这么多伤害~现在问你如何选择杀狼的顺序使的杀完所有狼时, ...

  7. hdu 4632 子字符串统计的区间dp

    题意:查找这样的子回文字符串(未必连续,但是有从左向右的顺序)个数. 简单的区间dp,哎,以为很神奇的东西,其实也是dp,只是参数改为区间,没做过此类型的题,想不到用dp,以后就 知道了,若已经知道[ ...

  8. HDU 2517 / POJ 1191 棋盘分割 区间DP / 记忆化搜索

    题目链接: 黑书 P116 HDU 2157 棋盘分割 POJ 1191 棋盘分割 分析:  枚举所有可能的切割方法. 但如果用递归的方法要加上记忆搜索, 不能会超时... 代码: #include& ...

  9. hdu 2476 (string painter) ( 字符串刷子 区间DP)

    String painter Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

随机推荐

  1. JS的prototype和__proto__ Constructor

    一.prototype和__proto__的概念 prototype是 注意是 只有函数的一个属性才有的(每个函数都有一个prototype属性),这个属性是一个指针,指向一个普通对象并且不是原型对象 ...

  2. 利用JSDOC快速生成注释文档,非常棒。

    有时往往我们需要建一个文档来记录js中的一些代码注释,比如一些公共的函数,又或者一些类,在团队合作中,文档接口也是必不可少的,传统的方式多少有些不便,这里介绍一个工具,它叫JSDOC,它可以用来将注释 ...

  3. C++中“类”相关知识点汇总

    一:类中默认的成员函数 一个空的class在C++编译器处理过后就不再为空,编译器会自动地为我们声明一些member function,如果你写 class Empty{}; 就相当于: class ...

  4. Git-图文教程

    https://github.com/haveatry823/QSanguoshaAI/wiki/Git-%E5%9B%BE%E6%96%87%E6%95%99%E7%A8%8B http://www ...

  5. Unity3D 为什么保存Transform等引用效率会更高

    正常来说,大部分同学一般get transform都直接gameobject.transform使用.但往往,你会发现有些人会将transform引用保存起来,例如:   private Transf ...

  6. javascript类型系统——Math对象

    × 目录 [1]常量 [2]函数 前面的话 javascript使用算术运算符实现基本的算术运算,如果要实现更加复杂的算术运算,需要通过Math对象定义的常量和函数来实现.和其他对象不同,Math只是 ...

  7. js返回上一页并刷新的多种实现方法

    <a href="javascript:history.go(-1)">返回上一页</a> <a href="javascript:loca ...

  8. Cocos2d-x 3.2 学习笔记(十四)保卫萝卜之界面UI

         保卫萝卜~上一篇说了使用CocoStudio制作主界面,这里来完善主界面动画及后续界面(主题界面ThemeUI.场景选择界面SelectMapUI),主要涉及的控件PageView. 学习要 ...

  9. Yii的学习(2)--数据访问对象 (DAO)

    摘自Yii官网:http://www.yiiframework.com/doc/guide/1.1/zh_cn/database.dao Yii提供了强大的数据库编程支持.Yii数据访问对象(DAO) ...

  10. Bounce.js – 快速创建漂亮的 CSS3 动画效果

    Bounce.js 是一个用于制作漂亮的 CSS3 关键帧动画的 JavaScript 库,使用其特有的方式生成的动画效果.只需添加一个组件,选择预设,然后你就可以得到一个短网址或者导出为 CSS 代 ...