题目链接

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. Android开发学习之路-抢红包助手开发全攻略

    背景:新年之际,微信微博支付宝红包是到处飞,但是,自己的手速总是比别人慢一点最后导致红包没抢到,红包助手就应运而生. 需求:收到红包的时候进行提醒,然后跳转到红包的界面方便用户 思路:获取“读取通知信 ...

  2. Atitit 订单处理原理与功能设计attilax总结

    Atitit 订单处理原理与功能设计attilax总结 订单有三大订单分类,商品订单,充值支付订单,报名订单等..1 订单完成流程  "select * from orderv2 where ...

  3. KnockoutJS 3.X API 第四章 数据绑定(2) 控制流foreach绑定

    foreach绑定 foreach绑定主要用于循环展示监控数组属性中的每一个元素,一般用于table标签中 假设你有一个监控属性数组,每当您添加,删除或重新排序数组项时,绑定将有效地更新UI的DOM- ...

  4. input---checked小问题

    想必有很多做前端同学都遇到了这么一个问题. 那就是checkbox.那就是我们通过jquery设置选中的时候,发现checked属性已经设置上去了 但是选中的样式却没有. 我们做一个简单的测试:看下面 ...

  5. Enterprise Solution 应用程序开发框架培训

    一.系统架构 C# .NET 4.0 + Win Form + SQL Server 2005 二.五大核心模块 (菜单设计器Menu Designer,查询设计器Query Designer,报表设 ...

  6. poj1062昂贵的聘礼(Dijkstra**)

    /* 题意: 物主有一个物品,价值为P,地位为L, 以及一系列的替代品Ti和该替代品所对应的"优惠"Vi g[u][i] 表示的是u物品被i物品替换后的优惠价格!(u>0, ...

  7. SQL Server中的事务日志管理(8/9):优化日志吞吐量

    当一切正常时,没有必要特别留意什么是事务日志,它是如何工作的.你只要确保每个数据库都有正确的备份.当出现问题时,事务日志的理解对于采取修正操作是重要的,尤其在需要紧急恢复数据库到指定点时.这系列文章会 ...

  8. 关于MYSQL数据库安装方式及相关设置简要说明

    网上关于MYSQL的教程非常多,但都不是最新的,我这里只是针对最新版本的MY SQL 的安装与设置进行一个简要的说明,大部份操作都相同. 以下是按照WINDOWS 64位操作系统+MY SQL 5.6 ...

  9. 用Qt写软件系列五:一个安全防护软件的制作(3)

    引言 上一篇中讲述了工具箱的添加.通过一个水平布局管理器,我们将一系列的工具按钮组合到了一起,完成了工具箱的编写.本文在前面的基础上实现窗体分割效果.堆栈式窗口以及Tab选项卡. 窗体分割 窗体分割是 ...

  10. Redis 集群方案

    根据一些测试整理出来的一份方案(转自http://www.cnblogs.com/lulu/): 1. Redis 性能 对于redis 的一些简单测试,仅供参考: 测试环境:Redhat6.2 , ...