You Are the One

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6113    Accepted Submission(s): 2982

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
题意:像《非诚勿扰》这样的电视剧很受欢迎。
为了满足单身男孩的需求,TJUT举办了自己的节目。
演出在小礼堂举行,所以吸引了很多男孩和女孩。
现在有n个男孩报名。
一开始,n个男孩站成一排,一个一个走向舞台。
然而,导演突然知道,每个男孩都有屌丝D的价值,如果男孩是k第一个上舞台的,他的不快乐将是(k-1)*D,因为他要等(k-1)人。
幸运的是,在小大厅里有一个黑暗的房间,所以导演可以把男孩暂时放到黑暗的房间里,让他身后的男孩先上台。
因为黑洞洞的房间很窄,第一个进入黑洞洞的男孩必须在最后离开。
导演想通过暗室改变男生的顺序,所以对不开心的总结最少。
你能帮助他吗?
 
思路:我们设dp[i][j]为当队伍里只有i到j的人时不开心之和的最小值
我们由题易知对于区间(i,j),当i号第k个出场时,那么(i+1,i+k)区间里的人肯定比i先出场(因为i要第k个出场,那么i肯定是先进小黑屋了,(i+1,i+k)区间的人要不进小黑屋就是先出场,所以他们肯定是比i先出场的)
而(i+k+1,j)区间内的人肯定是比i后出场的,我们就可以得出状态转移方程(sum[i]表示前i个人屌丝D之和)
dp[i][j]=min(dp[i][j], dp[i+1][i+k] + d[i]*(k-1) + (sum[j]-sum[i+k])*k  +dp[i+k+1][j]  )
                比i先出场      i出场        此时i后面人的已经等了这么久   比i后出场
 
代码

#include<cstdio>
#include<algorithm>
using namespace std;
int s[];
int sum[];//前缀和
const int INF=1e9;
int dp[][];
int main(){
int t,k=;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
sum[]=;
for(int i=;i<=n;i++){
scanf("%d",&s[i]);
sum[i]=sum[i-]+s[i];
dp[i][i]=;
}
for(int i=;i<n;i++){
for(int j=;i+j<=n;j++){
dp[j][i+j]=INF;
for(int k=j;k<=i+j;k++){
//printf("%d\n",dp[j][i+j]);
dp[j][i+j]=min(dp[j][i+j],dp[j+][k]+(k-j)*s[j]+(k-j+)*(sum[i+j]-sum[k])+dp[k+][i+j]);
//printf("%d %d %d %d %d %d %d\n",k,dp[j+1][k],(k-j)*s[j],(i-k+j),(sum[i+j]-sum[k]),dp[k+1][i+j],dp[j][i+j]);
}
//printf("ww%d %d %d %d\n",i,j,i+j,dp[j][i+j]);
}
}
printf("Case #%d: %d\n",k++,dp[][n]);
}
return ;
}

hdu4283的更多相关文章

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

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

随机推荐

  1. net技术方案

    https://www.cnblogs.com/qyq0323/p/11765243.html https://yq.aliyun.com/articles/300527

  2. 编写Postgres扩展之五:代码组织和版本控制

    原文:http://big-elephants.com/2015-11/writing-postgres-extensions-part-v/ 编译:Tacey Wong 在关于编写Postgres扩 ...

  3. Sharding-JDBC介绍

    Sharding-JDBC是当当应用框架ddframe中,从关系型数据库模块dd-rdb中分离出来的数据库水平分片框架,实现透明化数据库分库分表访问.Sharding-JDBC是继dubbox和ela ...

  4. iOS 动画基础-显式动画

    摘要 显式动画 属性动画 CABasicAnimation *animation = [CABasicAnimation animation];         [self updateHandsAn ...

  5. Android拍照和从相册获取照片

    1.从相册获取照片 private void openAlumb() { //mRxPermissions:三方权限库 mRxPermissions .request(Manifest.permiss ...

  6. 7层网络以及5种Linux IO模型以及相应IO基础

    一.七层网络模型 OSI是Open System Interconnection的缩写,意为开放式系统互联.国际标准化组织(ISO)制定了OSI模型,该模型定义了不同计算机互联的标准,它是一个七层的. ...

  7. 第四篇:python基础之杂货铺

    在这一篇中我们将对上几篇的Python零碎的知识进行补充,即字符串的格式化输出,以及深浅拷贝,接下来我们将对这两种进行一一介绍. 一.字符串格式化输出 关于字符串的格式化输出,我们需要了解为什么需要字 ...

  8. java - day017 - 线程

    进程 操作系统中, 并行执行的任务 线程 进程内部, 并行执行的任务 进程包含线程 线程的创建 继承Thred 定义 Thred 的子类 重写 run() 方法 在 run() 方法中的代码, 是与其 ...

  9. css详解2

    1.伪类选择器 1.1.a标签的爱恨准则 LoVe HAte .一个冒号连接 1.2.a标签的示例 给a标签设置个颜色,生效了 <html lang="en"> < ...

  10. 新一代纳秒级高带宽仿真工具平台——HAC Express

          HAC Express是基于FPGA的模型仿真开发环境,专注于高精度建模和超高速实时仿真,弥补了传统仿真工具平台无法进行纳秒级仿真的短板.         HAC系列自推出以来,经历了从v ...