HDU
来源:互联网 发布:品类管理数据分析 编辑:程序博客网 时间:2024/06/07 15:16
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)
2 512345554322
Case #1: 20Case #2: 24
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <cmath>using namespace std;typedef long long LL;typedef long double LD;const int inf = 0x3f3f3f3f;const LL INF = 0x3f3f3f3f3f3f3f3fll;const int maxn = 100+10;int T,N;int value[maxn];int dp[maxn][maxn];int sum[maxn];int main(){scanf("%d",&T);for(int t = 1; t <= T; t++){scanf("%d",&N);memset(sum,0,sizeof(sum));for(int i = 1; i <= N; i++)for(int j = 1; j <= N; j++){if(j<=i)dp[i][j] = 0;elsedp[i][j] = inf;}for(int i = 1; i <= N; i++){scanf("%d",&value[i]);sum[i] = sum[i-1]+value[i];//维护前缀和}for(int l = 1; l <= N; l++){//区间长度for(int i = 1; i+l-1 <= N; i++){//区间开头int j = i+l-1;//区间结尾for(int k = 1; k <= l; k++){//第i个人可以在(k的范围内)上场dp[i][j] = min(dp[i][j],dp[i+1][i+k-1]+dp[i+k][j]+value[i]*(k-1)+k*(sum[j]-sum[i+k-1]));//dp[i+1][i+k-1] -- 比第i个人先上场的(k-1)个人所转化的子问题//dp[i+k][j] -- 比第i个人后上场的(j-i+1-k)个人所转化的子问题//k*(sum[j]-sum[i+k-1]) -- 比第i个人后上场的(j-i+1-k)个人所贡献的屌丝值//value[i]*(k-1) -- 第i个人上场后所贡献的屌丝值}}}printf("Case #%d: %d\n",t,dp[1][N]);}return 0;}
阅读全文
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- 闲扯B-Tree和B+Tree的异同
- Hadoop集群搭建及测试过程中碰到的问题汇总
- 带有和夏天很配的逐浪字体+美食设计
- 深入理解Java的接口和抽象类
- Java疯狂讲义读书笔记第八章
- HDU
- The best way of parsing xml
- 非常详细的weblogic使用教程以及集群配置
- 将后台中获取的值传到select,并将左边select的值移到右边,将select的全部值传到后台
- LeetCode 349. Intersection of Two Arrays
- hdu 2029 Palindromes _easy version
- opencv总结1
- 使用TCP协议的NAT穿透技术 (转)
- 第一篇博客。