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. Nacos笔记01——使用Nacos作为SpringCloud项目的服务注册中心

    前言 刚学SpringCloud时使用eureka作为服务注册中心,随着网飞公司eureka2.x不再更新,以及最近在公司实习接触到的SpringCloud项目是使用Nacos来做服务注册中心的,所以 ...

  2. vue的交互

    交互     Vue做交互需要引入一个库:vue-resouce.js     get:      post     jsonp   <script src="vue.js" ...

  3. php权限管理

    首先权限管理肯定是需要登陆的,这里就简单的写一个登陆页面. 简单的登陆页面login.php <h1>登录页面</h1> <form action="login ...

  4. 攻防世界(Ctf-Web 新手练习区 Writeup)

    平台地址:adworld.xctf.org.cn 在打着暑假工赚零花钱之余,我将这些题利用空余时间刷了一遍,感觉内心还是比较满足的! 题目:view_source 这道题没啥好说的,在url的前面加上 ...

  5. K2 BPM_康熙别烦恼(下篇)——审批矩阵_工作流引擎

    康熙别烦恼(上篇)——分级授权 End 公司介绍:上海斯歌信息技术有限公司,聚焦企业所关注的管理挑战和压力,提供BPM平台及相关解决方案为主.2005年正式进入大中华地区,总部设在上海,并在北京.深圳 ...

  6. synchronize与lock

    1. synchronize的作用 synchronize是java最原始的同步关键字,通过对方法或者代码块进行加锁实现对临界区域的保护.线程每次进去同步方法或者代码块都需要申请锁,如果锁被占用则会等 ...

  7. java中级面试题

    1.Java中堆和栈有什么不同? 每个线程都有自己的栈内存,用于存储本地变量,方法参数和栈调用,一个线程中存储的变量对其它线程是不可见的.而堆是所有线程共享的一片公用内存区域.对象都在堆里创建,为了提 ...

  8. Hystrix原理与实战

    Hystrix原理与实战 背景 分布式系统环境下,服务间类似依赖非常常见,一个业务调用通常依赖多个基础服务. 比如:订单服务调用商品服务,商品服务调用库存服务. 对于同步调用,当库存服务不可用时,商品 ...

  9. 实现数字转换RMB大写~

    实现的功能是将数字“673”转换成“陆佰柒拾叁”    “3681”转换成“叁仟陆佰捌拾壹”     “8007”转换成“捌仟零柒” 主要使用了数组和循环来实现 代码雏形 package com.te ...

  10. NSIP

    1. 第一章 信息安全概述 信息:信息是有意义的数据,具有一定的价值,是一种适当保护的资产,数据是是客观事务属性的记录,是信息的具体表现形式,数据经过加工处理之后 就是信息,而信息需要经过数字处理转换 ...