HDU 4283 You are the one(间隔DP)
标题效果:
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?
解题思路:
区间DP,dp[i][j]表示从i到j的沮丧值。枚举第i个人的出场顺序。
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define LL long long
using namespace std;
const int MAXN = 100 + 10;
const int inf = 0x3f3f3f3f;
int dp[MAXN][MAXN];
int a[MAXN], sum[MAXN];
int N;
int main()
{
int T, kcase = 1;
scanf("%d", &T);
while(T--)
{
scanf("%d", &N);
memset(sum, 0, sizeof(sum));
memset(dp, 0, sizeof(dp));
for(int i=1;i<=N;i++)
{
scanf("%d", &a[i]);
sum[i] = sum[i-1] + a[i];
}
memset(dp, 0, sizeof(dp));
for(int i=1;i<=N;i++)
{
for(int j=i+1;j<=N;j++)
dp[i][j] = inf;
}
for(int len=1;len<N;len++)
{
for(int i=1;i+len<=N;i++)
{
int j = i + len;
for(int k=1;k<=j-i+1;k++)//第i个人第K个上场
{
dp[i][j] = min(dp[i][j], dp[i+1][i+k-1] + a[i] * (k-1) + dp[i+k][j] + k * (sum[j] - sum[i+k-1]));
/*dp[i+1][i+k-1]表示前k-1个人的沮丧值,a[i] * (k-1)表示第i个人的沮丧值。而i+k到j的这些人因为出场位置都添加了K。所以总的沮丧值添加了k * (sum[j] - sum[i+k-1])。*/
}
}
}
printf("Case #%d: %d\n", kcase++, dp[1][N]);
}
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
HDU 4283 You are the one(间隔DP)的更多相关文章
- hdu 4283 You Are the One 区间dp
You Are the One Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 4283"You Are the One"(区间DP)
传送门 https://www.cnblogs.com/violet-acmer/p/9852294.html 题意: 有n个屌丝排成一排,每个屌丝都有一个不开心值a[ i ]( i=1,2,3,.. ...
- HDU 4283 You Are the One ——区间dp
参考了许多大佬 尤其是https://blog.csdn.net/woshi250hua/article/details/7973824这一篇 ,最后我再加一点我的见解. 大意是 给定一个序列,序列 ...
- HDU 4283 (第k个出场 区间DP)
http://blog.csdn.net/acm_cxlove/article/details/7964594 http://www.tuicool.com/articles/jyaQ7n http: ...
- hdu 4283 区间dp
You Are the One Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu 5025 Saving Tang Monk 状态压缩dp+广搜
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092939.html 题目链接:hdu 5025 Saving Tang Monk 状态压缩 ...
- HDU 3016 Man Down (线段树+dp)
HDU 3016 Man Down (线段树+dp) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- POJ 3280 间隔DP
字符串,每次插入或删除字符需要一定的价格,问:我怎样才能使这个字符串转换成字符串回文,花最少. 间隔DP 当DP到区间[i,j+1]时,我们能够在i-1的位置加入一个str[j+1]字符,或者将在j+ ...
- HDU 3341 Lost's revenge AC自动机+dp
Lost's revenge Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)T ...
- HDU 2457 DNA repair(AC自动机+DP)题解
题意:给你几个模式串,问你主串最少改几个字符能够使主串不包含模式串 思路:从昨天中午开始研究,研究到现在终于看懂了.既然是多模匹配,我们是要用到AC自动机的.我们把主串放到AC自动机上跑,并保证不出现 ...
随机推荐
- mongodb实现简单的增删改查
package mongoDB; import java.net.UnknownHostException; import java.util.ArrayList; import java.util. ...
- NET MVC运行机制
[图解ASP.NET MVC运行机制理解-简易版] 很多盆友咨询ASP.NET MVC的机制.网上也有好多.但是都是相当深奥.看的云里雾里的.我今天抽空,整理个简易版本.把处理流程走一遍. 当然, ...
- windows phone (24) Canvas元素A
原文:windows phone (24) Canvas元素A Canvas元素表示定制一个区域,并可以通过相对坐标定义子元素位置,在一下情况下Canvas是不可见的 Height 属性等于 0. W ...
- C语言程序代写(qq:928900200)
1cs3157 – Advanced ProgrammingSummer 2014, Project 1, 150 pointsJune 17, 2014Follow these step-by-st ...
- WPF/Silverlight中图形的平移,缩放,旋转,倾斜变换演示
原文:WPF/Silverlight中图形的平移,缩放,旋转,倾斜变换演示 为方便描述, 这里仅以正方形来做演示, 其他图形从略. 运行时效果图:XAML代码:// Transform.XAML< ...
- [Windows Phone] 在 Windows Phone 8 控制闪光灯
原文:[Windows Phone] 在 Windows Phone 8 控制闪光灯 ? 前言 在 Windows Phone 如果想要控制闪光灯,该怎麽做?在 Windows Phone 8 提供类 ...
- POJ2239 Selecting Courses【二部图最大匹配】
主题链接: http://poj.org/problem?id=2239 题目大意: 学校总共同拥有N门课程,而且学校规定每天上12节可,一周上7天. 给你每门课每周上的次数,和哪一天哪一节 课上的. ...
- effective c++ 条款13 use object to manage resources.
请求的系统资源需要最终还回系统,为了避免遗忘返还这个动作,可以利用析构函数在object销毁时自动调用的特点来实现. 简单说就是用object来管理资源. 以内存资源为例 class Investme ...
- 【android】优秀的UI资源站点集合
1.http://ionicons.com/ 这个站点的图标能满足大部分人的需求.里面包括了经常使用的android风格的图标 ios7风格的图标 以及一些社会化分享图标,总共500个左右.githu ...
- lua基金会【五岁以下儿童】I/O文件操作
--[[ lua操作相关文件I/O ]]-- --件,假设该文件不存在的话, --lua会帮助我们在你规定的文件夹下创建这个文件,前提是该文件夹要存在 --[[ 同一时候我们应该掌握写入文件的模式: ...