传送门

题目

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?

Input
The first line contains a single integer T, the number of test cases.  For each case, the first line is n (0 < n <= 100)
The next n line are n integer D1-Dn means the value of diaosi of boys (0 <= Di <= 100)
Output

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

  1. HDU4283 You Are the One —— 区间DP

    题目链接:https://vjudge.net/problem/HDU-4283 You Are the One Time Limit: 2000/1000 MS (Java/Others)    M ...

  2. hdu4283 区间dp

    //Accepted 300 KB 0 ms //区间dp //dp[i][j] 表示i到j第一个出场的最小diaosizhi //对于i到j考虑元素i //(1)i第一个出场,diaosizhi为 ...

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

  4. hdu4283(区间dp)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4283 题意:有一个队列,每个人有一个愤怒值D,如果他是第K个上场,不开心指数就为(K-1)*D.但是边 ...

  5. hdu4283 You Are the One 区间DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4283 自己想了很久还是不会,参考了别人的思路才写的,区间DP还是很弱,继续努力!! 思路: 转载: 题 ...

  6. HDU4283(KB22-G)

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

  7. hdu-4283 You Are the One 区间dp,

    题意:n个人排队上台,每个人有一屌丝值D,他的不满意值=D*(k-1)(k为他前面的总人数). 求整个队列不满意值之和的最小值.你只有一个操作,就是把队首的人塞进小黑屋,也就是压入栈中,后面的人就被提 ...

  8. 刷题总结——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 ...

  9. hdu4283

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

随机推荐

  1. kvm-控制台登陆配置

    vm虚拟机能否像xen虚拟机一样通过virsh console 一样采用字符界面进行linux虚拟机控制台呢,答案是肯定的,默认情况下该命令是不起作用的,需要修改相关文件才能实现. 1. 配置方法如下 ...

  2. nyoj-158-省赛来了(组合数)

    题目链接 /* Name:nyoj-158-省赛来了 Copyright: Author: Date: 2018/4/25 17:07:22 Description: 暴力,秒天秒地 */ #incl ...

  3. C++结构体成员列表初始化

    C++关于struct和class的区别,可以看上一篇文章:c ++ class和struct[转] 结构体成员列表初始化,来个例子: #include <iostream> #inclu ...

  4. OpenCV教程【002 VideoCapture加载并播放视频】

    #include <opencv2/opencv.hpp> #include <iostream> using namespace std; using namespace c ...

  5. Agc007_C Pushing Balls

    传送门 题目大意 在一条直线上有$N$个球和$N+1$个洞,每两个球之间有一个洞,每两个洞之间有一个球,最左端和最右端都是洞,其中产生的$2N$个间隔满足从左到右是等差数列.你每次随机选择一个未被推进 ...

  6. EF各版本增删查改及执行Sql语句

    自从我开始使用Visual Studio 也已经经历了好几个版本了,而且这中间EF等框架的改变也算是比较多的.本篇文章记录下各个版本EF执行Sql语句和直接进行增删查改操作的区别,方便自己随时切换版本 ...

  7. 证书脚本--生成csr,key

    #!/bin/sh # this script can make certificate of each line in file you point which one! if [ $# -ne 1 ...

  8. 蓝桥杯 算法训练 ALGO-121 猴子分苹果

      算法训练 猴子分苹果   时间限制:1.0s   内存限制:256.0MB 问题描述 秋天到了,n只猴子采摘了一大堆苹果放到山洞里,约定第二天平分.这些猴子很崇拜猴王孙悟空,所以都想给他留一些苹果 ...

  9. mysql函数之三:find_in_set() 函数 返回str在字符串集strlist中的序号

    如果字符串str是在的strlist组成的N子串的字符串列表,返回值的范围为1到N. FIND_IN_SET(str,strlist) 如果字符串str是在的strlist组成的N子串的字符串列表,返 ...

  10. Java-API-Package:javax.http.servlet

    ylbtech-Java-API-Package:javax.http.servlet 1.返回顶部 1. Package javax.servlet.http This chapter descri ...