标题效果:

  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. java + memcached安装

    一:安装 (临时获取上手windows实验) 1.下载memcached.exe , 上F:\memcached\ 下 2.在CMD在输入 "F:\memcached\memcached.e ...

  2. Bestcoder Round#45

    1001 给定数n,要我们求该数的二进制中有多少组1, 相邻的1称为1组, 直接位运算摸你即可 #include <stdio.h> #include <string.h> # ...

  3. 关于mysql主从复制的概述与分类(转)

    一.概述: 按照MySQL的同步复制特点,大体上可以分为三种类别: 1.异步复制: 2.半同步复制: 3.完全同步的复制: -------------------------------------- ...

  4. (算法入门经典大赛 优先级队列)LA 3135(之前K说明)

    A data stream is a real-time, continuous, ordered sequence of items. Some examples include sensor da ...

  5. 使用Spring的@Autowired 实现DAO, Service, Controller三层的注入(转)

    简述: 结合Spring和Hibernate进行开发 使用@Autowired实现依赖注入, 实现一个学生注册的功能,做一个技术原型 从DAO(Repository) -> Service -& ...

  6. Arduino 数码管LED驱动 数组法

    上个样例讲到驱动LED数码管,採用一种最直接的方案,对每一个LED进行高低电平的控制,这种长处是每一个LED都是受控可检的,避免了因为短路造成的假象,但对于数字变化来说,写起来就很冗余,因此这次尝试用 ...

  7. php zip文件内容比較类

    php zip 文件比較类,比較两个zip文件的内容,返回新增,删除,及同样的文件列表.临时仅仅支持单层. 需求:上传一个zip文件,zip内有非常多图片文件.须要对图片文件进行一系列非常耗时的处理. ...

  8. sizeClass和autolayout学习资源整理

    sizeClass和autolayout,看来不得不開始放弃frame的写法,收集点资料集中学习下 Adaptivity User Interfaces苹果官方文档:https://developer ...

  9. Directx11学习笔记【十七】纹理贴图

    本文由zhangbaochong原创,转载请注明出处http://www.cnblogs.com/zhangbaochong/p/5596180.html 在之前的例子中,我们实现了光照和材质使得场景 ...

  10. 改动symbol link的owner

    当/home/jenkins文件夹空间不足的时候,能够先查看哪个文件夹在较大的磁盘分区上,然后将jenkins文件夹移动过去 最后创建/home/jenkins link到新位置. 这时候须要改动sy ...