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. javscript函数的运用

    函数,一段能够自动完成某些功能的代码块,函数的出现,既解决了重复使用重一功能的需求,又可以避免代码的臃肿性. 使用函数有两个要求:必须调用后才可以执行;函数名不要和关键字以及系统函数相同; 函数主要有 ...

  2. MySQL删除表操作(delete、truncate、drop的区别)

    简介delete1.删除整张表的数据: delete from table_name; 2.删除部分数据,添加where子句: delete from table_name where...; 3.说 ...

  3. 关于ubuntu软件图标的问题

    原因是这样的,有一次我更新我的IDEA之后,程序图标就不见了. 怎么说呢,就是以下显示的这样. 在Frequent中显示正常, 在All中却没有!!! 是的,它就是在一边有一边没有... 奇了怪了. ...

  4. Kubernetes 1.14发布:对Windows节点的生产级支持、Kubectl更新与持久本地卷通用版本已全面到来

    今天,我们高兴地宣布Kubernetes 1.14版本的正式亮相,这亦是我们在2019年当中进行的首次发布!Kubernetes 1.14版本由31项增强功能组成,具体包括:10项稳定版功能,12项b ...

  5. Codeforces #366 Div. 2 C. Thor (模拟

    http://codeforces.com/contest/705/problem/C 题目 模拟题 : 设的方法采用一个 r 数组(第几个app已经阅读过的消息的数量),和app数组(第几个app发 ...

  6. P1363 幻象迷宫[搜索]

    题目描述 (喵星人LHX和WD同心协力击退了汪星人的入侵,不幸的是,汪星人撤退之前给它们制造了一片幻象迷宫.) WD:呜呜,肿么办啊-- LHX:momo...我们一定能走出去的! WD:嗯,+U+U ...

  7. Caused by: java.lang.ClassNotFoundException: org.fusesource.jansi.WindowsAnsiOutputStream

    08:23:18,995 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate append ...

  8. 前端学习笔记--CSS布局--盒子模型

    1.概述: 2.盒子模型 overflow属性: border属性: 1.padding属性: margin:

  9. appium 使用name 定位报错 Locator Strategy 'name' is not supported for this session

    RF中使用 name定位 报错提示: Locator Strategy 'name' is not supported for this session 解决: 1. 打开本地文件 driver.js ...

  10. python_面向对象——多态

    1.同一接口,多种形态 class Document: def __init__(self,name): self.name = name def show(self): # 异常处理:提示子类必须把 ...