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. Java Web-Ajax学习

    Java Web-Ajax学习 概念 Ajax(Asynchronous JavaScript And XML,异步的JavaScript和XML). 异步和同步:在客户端和服务器端相互通信的基础上来 ...

  2. log4net SmtpAppender 踩坑总结

    错误集合: System.Net.Mail.SmtpException: 命令顺序不正确. 服务器响应为:Error: need EHLO and AUTH first ! System.Net.Ma ...

  3. VBA Excel对象(十九)

    使用VBA进行编程时,用户将要处理的重要对象很少.下面是一些常见的对象 - 应用程序对象 工作簿对象 工作表对象 范围对象 应用程序对象 应用程序对象由以下部分组成 - 应用程序范围的设置和选项. 返 ...

  4. axios拦截登陆过期请求多次

    request.interceptors.response.use( response => { console.log(response.data.code) // console.log(r ...

  5. python使用Pyinstaller打包

    一.前言 python文件打包,将.py文件转化成.exe文件(windows平台),可以使用Pyinstaller来打包 Pyinstaller可以在全平台下使用,但是请注意打包生成的文件不能在全平 ...

  6. py-1 语言介绍

    一.编程与编程语言 1.编程的目的 计算机的发明,是为了用机器取代并解放人力.而编程的目的则是将人类的思想流程按照某种能够被计算机识别的表达方式传递给计算机,从而达到让计算机能够像人脑.电脑一样自动执 ...

  7. Codeforces #366 (Div. 2) D. Ant Man (贪心)

    https://blog.csdn.net/liangzhaoyang1/article/details/52215276  原博客 原来好像是个dp题,不过我看了别人的博客使用贪心做的 复杂度(n^ ...

  8. uWSGI ,WSGI和uwsgi的区别

    1.1.为方便理解,uWSGI ,WSGI和uwsgi在网站项目流程图中的功能如下: 1.2.网站项目结构图 2.uWSGI ,WSGI和uwsgi的区别 2.1 WSGI: WSGI,全称 Web ...

  9. python 根据两个字段排序, 一个升序, 一个降序

    from collections import Counter c = Counter(input()) l=sorted(c.items(), key=lambda s:(-s[], s[])) ] ...

  10. 26 组件中style标签lang属性和scoped属性的介绍

    普通的style标签只支持普通的样式,如果想要启用scss或less,需要为style元素,设置lang属性 只要 咱们的style标签,是在 .vue 组件中定义的,那么,推荐都为style开启sc ...