hdu4283 You Are the One
题目
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?
The next n line are n integer D1-Dn means the value of diaosi of boys (0 <= Di <= 100)
For each test case, output the least summary of unhappiness .
题目大意
有n个人,输入n个基值(愤怒值)v[],表示每个人的愤怒值,现在他们依次上台表演,如果i是第k个上台,那么他的愤怒值为(k-1)*v[i] 现在有一个栈,可以让一些人进栈,让后面的人先上台表演,这样可以改变部分顺序,求所有人最小的愤怒值和。
分析
用dpij表示i到j区间的人的最小值,我们枚举考虑的区间的长度和起点,并枚举这段区间的第一个人是在第几个登场,注意特判这个人第一个和最后一个登场的情况。为了集体后移时的计算方便,我们记录一个前缀和。具体转移方程等见代码。
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int dp[][],sum[],v[];
int main()
{ int n,m,i,j,k,t,p;
scanf("%d",&t);
for(p=;p<=t;p++){
scanf("%d",&n);
sum[]=;
for(i=;i<=n;i++){
scanf("%d",&v[i]);
sum[i]=sum[i-]+v[i];
dp[i][i]=;
}
for(i=;i<n;i++)
for(j=;j+i<=n;j++){
dp[j][j+i]=min(sum[j+i]-sum[j]+dp[j+][j+i],dp[j+][j+i]+v[j]*i);
for(k=;k<=i;k++)
dp[j][j+i]=min(dp[j][j+i],dp[j+k][j+i]+dp[j+][j+k-]+v[j]*(k-)+(sum[j+i]-sum[j+k-])*k);
}
printf("Case #%d: %d\n",p,dp[][n]);
}
return ;
}
hdu4283 You Are the One的更多相关文章
- HDU4283 You Are the One —— 区间DP
题目链接:https://vjudge.net/problem/HDU-4283 You Are the One Time Limit: 2000/1000 MS (Java/Others) M ...
- hdu4283 区间dp
//Accepted 300 KB 0 ms //区间dp //dp[i][j] 表示i到j第一个出场的最小diaosizhi //对于i到j考虑元素i //(1)i第一个出场,diaosizhi为 ...
- HDU4283:You Are the One(区间DP)
Problem Description The TV shows such as You Are the One has been very popular. In order to meet the ...
- hdu4283(区间dp)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4283 题意:有一个队列,每个人有一个愤怒值D,如果他是第K个上场,不开心指数就为(K-1)*D.但是边 ...
- hdu4283 You Are the One 区间DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4283 自己想了很久还是不会,参考了别人的思路才写的,区间DP还是很弱,继续努力!! 思路: 转载: 题 ...
- HDU4283(KB22-G)
You Are the One Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu-4283 You Are the One 区间dp,
题意:n个人排队上台,每个人有一屌丝值D,他的不满意值=D*(k-1)(k为他前面的总人数). 求整个队列不满意值之和的最小值.你只有一个操作,就是把队首的人塞进小黑屋,也就是压入栈中,后面的人就被提 ...
- 刷题总结——you are the one(hdu4283)
题目: The TV shows such as You Are the One has been very popular. In order to meet the need of boys wh ...
- hdu4283
You Are the One Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- php中实现将姓名拆分为姓氏和名字
之前有分享了用javascript在客户端进行姓名拆分的方法,后应项目需要,又用PHP实现了,贴出来 跟大家分享交流: /** * 把全名拆分为姓氏和名字 * @param string $fulln ...
- BEC translation exercise 4
People have long known that nuts are part of a healthy diet.人们早就知道坚果是健康饮食的一部分.People, who you know w ...
- 使用Python和OpenCV通过网址URL获取图片
在OpenCV中通过图片的URL地址获取图片: # -*- coding: utf-8 -*- import numpy as np import urllib import cv2 # URL到图片 ...
- Find The Multiple(DFS)
Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal repr ...
- LeetCode Distribute Candies
原题链接在这里:https://leetcode.com/problems/distribute-candies/#/description 题目: Given an integer array wi ...
- bzoj 3709: [PA2014]Bohater 贪心
题目: 在一款电脑游戏中,你需要打败\(n\)只怪物(从\(1\)到\(n\)编号).为了打败第\(i\)只怪物,你需要消耗\(d_i\)点生命值,但怪物死后会掉落血药,使你恢复\(a_i\)点生命值 ...
- dubbo的监控中心
监控中心实际上就是一个web工程. 是dubbo官方给我们提供的一个war包. 只需要部署在Tomcat中就可以了. 推荐把监控中心与注册中心部署在一台服务器上,这样可以不需要任何配置. 部署完成后直 ...
- es5中foreach的用法
HTML代码: <p id="result"></p> JS代码: var eleResult = document.getElementById(&quo ...
- 在Mac系统下使用自己安装的PHP
今天在安装单元测试框架PHPUnit,需要PHP的最低版本是5.6,由于我的MacBook自带的PHP版本是5.5.36,不能满足安装条件. 看了一下这个网址:https://php-osx.liip ...
- GXT4.0 BorderLayoutContainer布局
T字型布局. @Override public void onModuleLoad() { BorderLayoutContainer con = new BorderLayoutContainer( ...