标题效果:

  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)的更多相关文章

  1. 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) ...

  2. hdu 4283"You Are the One"(区间DP)

    传送门 https://www.cnblogs.com/violet-acmer/p/9852294.html 题意: 有n个屌丝排成一排,每个屌丝都有一个不开心值a[ i ]( i=1,2,3,.. ...

  3. HDU 4283 You Are the One ——区间dp

    参考了许多大佬  尤其是https://blog.csdn.net/woshi250hua/article/details/7973824这一篇 ,最后我再加一点我的见解. 大意是 给定一个序列,序列 ...

  4. HDU 4283 (第k个出场 区间DP)

    http://blog.csdn.net/acm_cxlove/article/details/7964594 http://www.tuicool.com/articles/jyaQ7n http: ...

  5. hdu 4283 区间dp

    You Are the One Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  6. hdu 5025 Saving Tang Monk 状态压缩dp+广搜

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092939.html 题目链接:hdu 5025 Saving Tang Monk 状态压缩 ...

  7. HDU 3016 Man Down (线段树+dp)

    HDU 3016 Man Down (线段树+dp) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  8. POJ 3280 间隔DP

    字符串,每次插入或删除字符需要一定的价格,问:我怎样才能使这个字符串转换成字符串回文,花最少. 间隔DP 当DP到区间[i,j+1]时,我们能够在i-1的位置加入一个str[j+1]字符,或者将在j+ ...

  9. 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 ...

  10. HDU 2457 DNA repair(AC自动机+DP)题解

    题意:给你几个模式串,问你主串最少改几个字符能够使主串不包含模式串 思路:从昨天中午开始研究,研究到现在终于看懂了.既然是多模匹配,我们是要用到AC自动机的.我们把主串放到AC自动机上跑,并保证不出现 ...

随机推荐

  1. 【翻译】Why JavaScript Is and Will Continue to Be the First Choice of Programmers

    花费2半小时,那么最终会被翻译.假设有问题,请提出,毕竟,自己的6不超过级别. 附加链接 Why JavaScript Is and Will Continue to Be the First Cho ...

  2. STL algorithm算法minmax,minmax_element(36)

    minmax原型: std::minmax C++11 C++14 default (1) template <class T> pair <const T&,const T ...

  3. 跨平台移动框架iMAG开发入门

    iMAG是一个非常简洁高效的移动跨平台开发框架,开发一次能够同一时候兼容Android和iOS平台,有点儿Web开发基础就能非常快上手.当前移动端跨平台开发的框架有非常多,但用iMAG另一个优点,就是 ...

  4. Java并发学习之中的一个——线程的创建

    本文是学习网络上的文章时的总结,感谢大家无私的分享. 1.与每一个Java语言中的元素一样,线程是对象.在Java中,我们有两种方式创建线程: a.通过直接继承thread类,然后覆盖run方法. b ...

  5. JS判断用户连续输入

    方案1 // // $('#element').donetyping(callback[, timeout=1000]) // Fires callback when a user has finis ...

  6. iOS 在TabViewController中的一个ViewController跳转到另一种ViewController

    第一步: #import "AppDelegate.h" 步骤二: 在须要跳转的地方: AppDelegate *appDelegate = (AppDelegate *)[[UI ...

  7. 第三届蓝桥杯Java高职组决赛第三题

    题目描述: 某少年宫引进了一批机器人小车.可以接受预先输入的指令,按指令行动.小车的基本动作很简单,只有3种:左转(记为L),右转(记为R),向前走若干厘米(直接记数字). 例如,我们可以对小车输入如 ...

  8. 升级到cocos2d-x 2.0.2代码差异

    来自:http://www.cnblogs.com/TopWin/archive/2012/09/12/2682042.html 近期看cocos2d-x 2.0.2公布后升级了一下.升级后发现又出现 ...

  9. Android System Property 解析

    一 System Property       今天在折腾HDMI 显示,为Setting提供接口,遇到非常多跟Android系统属性相关的问题.因此,顺便分析和总结一些. android的代码中大量 ...

  10. 单链表的实现---SingleLinkedList

    单链表的实现,定义为SingleLinkedList class Node<AnyType>{ //结点Node类 public AnyType data; public Node< ...