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自动机上跑,并保证不出现 ...
随机推荐
- Apple Watch视频教程(连载)
发展Apple Watch 必须Xcode 6.2上述号码,所有视频.课件.Demo须要的能够加我私人微信 wanghj29(扫描头像也能够),在微信里面给我发email,我都发过去,另外也提供在线播 ...
- linux free
在Linux下查看内存我们一般用command free [root@nonamelinux ~]# free total used free s ...
- jspsmart(支持中文下载)
将excel文件从jsp页面导入到数据库,先将文件上传到server,然后读取,最后删除掉上传//要加encType="multipart/form-data"<form a ...
- leetcode先刷_Climbing Stairs
水的问题. 以为很常见.青蛙跳楼梯.能跳一步可以跳两步,它实际上是一个斐波那契数. 注意.空间O(1). class Solution { public: int climbStairs(int n) ...
- [转载][NAS] 使用win8的“存储池”功能~
之前自己用DQ77KB搭建一个小存储系统(帖子链接:http://www.chiphell.com/thread-567753-1-1.html),一直使用intel主板带的软RAID功能构建RAID ...
- 慎重使用MySQL auto_increment
在使用MySQL中,常常会在表中建立一个自增的ID字段,利用自增ID可以高速建立索引,也是MySQL官方比較推荐的一种方式,可是,这样的方式在大量数据且配置主从时,可能会出现因为自增ID导致同步失败的 ...
- bash组织成树数据结构
君子也非独占,善假于物!bash也因此.昨天晚上,今天早上世界杯很精彩.晚上醒来看到不断地居住的电话.早上没有喝的水开始赞赏在英国和意大利的对决.也TM精彩,最后生下了罗马文化.意大利伊特鲁里亚文化获 ...
- OPhone SDK初体验
OPhone SDK初体验 write by 九天雁翎(JTianLing) -- blog.csdn.net/vagrxie 讨论新闻组及文件 背景说明 中国伟大的垄断龙头,世界上也是顶尖的中移动最 ...
- HDU 4311 Meeting point-1 && HDU 4312 Meeting point-2
这俩个题 题意::给出N(<1e5)个点求找到一个点作为聚会的地方,使每个点到达这里的距离最小.4311是 曼哈顿距离 4312是 切比雪夫距离: 曼哈顿距离 :大家都知道 对于二维坐标系a( ...
- nginx+lua+redis构建高并发应用(转)
nginx+lua+redis构建高并发应用 ngx_lua将lua嵌入到nginx,让nginx执行lua脚本,高并发,非阻塞的处理各种请求. url请求nginx服务器,然后lua查询redis, ...