传送门

You Are the One

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

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
 
【题目大意】
n个人参加节目,每人都有一个屌丝值D,如果他第k个上场,那么他的不高兴值为(k-1)*D,因为他要等k-1个人。
节目有个小黑屋(是个栈,满足栈的性质)可以改变入场顺序。求最小不高兴值。
【思路】
区间dp。
现在上场的人的可能性有..栈顶的那个人,队伍中的那个人,队伍中的人进栈后,队首的那个人。
用dp[i][j]表示第i个人到第j个人的最小不高兴价值。
区间dp要进行区间合并,进行枚举断点k。
dp[i][j]由dp[i][k]和dp[k+1][j]转移而来。
可以第i--k个人先上舞台,k+1--j后上舞台。
也可以第k+1---j个人先上舞台,第i--k个人后上舞台,这就要求i--k这些人进栈,那么再上舞台的顺序就是原来的逆序,不高兴值预处理。
注意,对于dp[i][j]是个独立的区间,看成第i个就是这个区间的第一个进行处理。只需在合并时处理一下。
转移方程:
dp[i][j]=min(dp[i][j],min{dp[i][k]+dp[k+1][j]+(sum[j]-sum[k-1])*(k-i+1)  ,dp[k+1][j]+v[i][k]+(sum[k]-sum[i-1])*(j-k) }) 
转移方程指的是在上述两种情况中寻找最小值,其中sum是因为我们在处理dp[i][j]时是将i看做第一个处理的,
如果说i--k个先进入,k+1--j后进入(第一种情况),k+1--j每个人前面多了k-i+1个人,所以要加上产生的不高兴值。
记忆化搜索也可做。
最大值0x7fffffff(7个f为2147483647,3个f五位数)。
【code】
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define inf 0x7fffffff
int n,t,kas;
int sum[],v[][],dp[][],a[];
void befr() {
for(int i=; i<=n; i++)
for(int j=i-; j>=; j--)
v[j][i]=v[j+][i]+a[j]*(i-j);
}
int main() {
scanf("%d",&t);
while(t--) {
memset(sum,,sizeof(sum));
memset(v,,sizeof(v));
scanf("%d",&n);
for(int i=; i<=n; i++) {
scanf("%d",&a[i]);
sum[i]=sum[i-]+a[i];
}
for(int i=; i<=n; i++)
for(int j=; j<=n; j++)
if(i!=j)
dp[i][j]=inf;
else
dp[i][j]=;
befr();
for(int j=; j<=n; j++)
for(int i=j-; i>=; i--)
for(int k=i; k<j; k++) {
dp[i][j]=min(dp[i][j],min(dp[i][k]+dp[k+][j]+(sum[j]-sum[k])*(k-i+),dp[k+][j]+v[i][k]+(sum[k]-sum[i-])*(j-k)));
}
printf("Case #%d: %d\n",++kas, dp[][n]);
}
return ;
}

you are the one(区间dp)的更多相关文章

  1. 【BZOJ-4380】Myjnie 区间DP

    4380: [POI2015]Myjnie Time Limit: 40 Sec  Memory Limit: 256 MBSec  Special JudgeSubmit: 162  Solved: ...

  2. 【POJ-1390】Blocks 区间DP

    Blocks Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5252   Accepted: 2165 Descriptio ...

  3. 区间DP LightOJ 1422 Halloween Costumes

    http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...

  4. BZOJ1055: [HAOI2008]玩具取名[区间DP]

    1055: [HAOI2008]玩具取名 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1588  Solved: 925[Submit][Statu ...

  5. poj2955 Brackets (区间dp)

    题目链接:http://poj.org/problem?id=2955 题意:给定字符串 求括号匹配最多时的子串长度. 区间dp,状态转移方程: dp[i][j]=max ( dp[i][j] , 2 ...

  6. HDU5900 QSC and Master(区间DP + 最小费用最大流)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5900 Description Every school has some legends, ...

  7. BZOJ 1260&UVa 4394 区间DP

    题意: 给一段字符串成段染色,问染成目标串最少次数. SOL: 区间DP... DP[i][j]表示从i染到j最小代价 转移:dp[i][j]=min(dp[i][j],dp[i+1][k]+dp[k ...

  8. 区间dp总结篇

    前言:这两天没有写什么题目,把前两周做的有些意思的背包题和最长递增.公共子序列写了个总结.反过去写总结,总能让自己有一番收获......就区间dp来说,一开始我完全不明白它是怎么应用的,甚至于看解题报 ...

  9. Uva 10891 经典博弈区间DP

    经典博弈区间DP 题目链接:https://uva.onlinejudge.org/external/108/p10891.pdf 题意: 给定n个数字,A和B可以从这串数字的两端任意选数字,一次只能 ...

  10. 2016 年沈阳网络赛---QSC and Master(区间DP)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5900 Problem Description Every school has some legend ...

随机推荐

  1. 发布npm包

    来源:https://segmentfault.com/a/1190000010398983

  2. ros使用罗技f710无线控制手柄

    参考:blog.csdn.net/hcx25909/article/details/9042469 罗技F710无线控制手柄ROS下使用说明 安装手柄相关的包和驱动 sudo apt-get inst ...

  3. Eclipse FindBugs的安装

    原文:http://blog.sina.com.cn/s/blog_62186b460100l3mx.html 1安装:首先到官方网站下载最新版本FindBugs    http://findbugs ...

  4. 使用Myeclipse + SVN + TaoCode 免费实现项目版本控制的详细教程

    通过Myeclipse + SVN插件 + TaoCOde可以省去代码仓库的租建:同时还可以很好的满足小团队之间敏捷开发的需求.接下来详细介绍整个搭建流程. 首先,介绍所用到的工具: 1,Myecli ...

  5. ASP.NET Core 如何记录每次请求的Request信息 - sky 胡萝卜星星 - CSDN博客

    原文:ASP.NET Core 如何记录每次请求的Request信息 - sky 胡萝卜星星 - CSDN博客 版权声明:本文为starfd原创文章,转载请标明出处. https://blog.csd ...

  6. Linux索引节点(Inode:no space for device)用满导致的一次故障

    问题描写叙述 在storm測试环境集群上上nimbus和supervisor自己主动挂调.重新启动时显示no space for device,也不能创建,加入文件及文件夹,df -h查看 ilesy ...

  7. 基于Lua插件化的Pcap流量监听代理

    1.前言 我们在实际工作中,遇到了一个这样的用例,在每天例行扫描活动中,发现有些应用系统不定期的被扫挂,因为我们不是服务的制造者,没有办法在不同的系统里打印日志,所以我们就想用一个工具来获取特定服务的 ...

  8. binary-tree-preorder-traversal——前序遍历

    Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binary tr ...

  9. Katalon

    Katalon---一款好用的selenium自动化测试插件 selenium框架是目前使用较广泛的开源自动化框架,一款好的.基于界面的录制工具对于初学者来说可以快速入门:对于老手来说可以提高开发自动 ...

  10. spinlock,mutex,semaphore,critical section的作用与差别

    某年深信服的笔试题,考的就是多线程的同步.简单的解释下方便记忆: 1.spinlock:自旋锁.是专为防止多处理器并发而引入的一种锁. 2.mutex:相互排斥量. 仅仅有拥有相互排斥对象的线程才有訪 ...