You Are the One

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Problem Description
 
 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 .
 
Sample Input
2
  
5
1
2
3
4
5

5
5
4
3
2
2

 
Sample Output
Case #1: 20
Case #2: 24
 
Source
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = ,inf=1e9+;
int a[N],pre[N];
int dp[N][N];
int main()
{
int T,cas=;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
pre[i]=pre[i-]+a[i];
}
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)
{
for(int j=i;j<=n;j++)
dp[i][j]=inf;
}
for(int i=;i<=n;i++)
{
for(int j=;j+i-<=n;j++)
{
int st=j;
int en=j+i-;
for(int k=st;k<=en;k++)
{
int p=k-st+;
dp[st][en]=min(dp[st][en],dp[st+][k]+dp[k+][en]+p*a[st]+(pre[en]-pre[k])*p);
}
}
}
printf("Case #%d: %d\n",cas++,dp[][n]-(pre[n]));
}
return ;
}
/*
2
5
1 2 3 4 5
5
5 4 3 2 2
*/

hdu 4283 You Are the One 区间dp的更多相关文章

  1. hdu 4283"You Are the One"(区间DP)

    传送门 https://www.cnblogs.com/violet-acmer/p/9852294.html 题意: 有n个屌丝排成一排,每个屌丝都有一个不开心值a[ i ]( i=1,2,3,.. ...

  2. HDU 4283 You Are the One ——区间dp

    参考了许多大佬  尤其是https://blog.csdn.net/woshi250hua/article/details/7973824这一篇 ,最后我再加一点我的见解. 大意是 给定一个序列,序列 ...

  3. HDU 4283 (第k个出场 区间DP)

    http://blog.csdn.net/acm_cxlove/article/details/7964594 http://www.tuicool.com/articles/jyaQ7n http: ...

  4. HDU 4283---You Are the One(区间DP)

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=4283 Problem Description The TV shows such as Y ...

  5. HDU 5900 QSC and Master (区间DP)

    题目链接   http://acm.hdu.edu.cn/showproblem.php?pid=5900 题意:给出序列$A_{i}.key$和$A_{i}.value$,若当前相邻的两个数$A_{ ...

  6. HDU 5115 (杀狼,区间DP)

    题意:你是一个战士现在面对,一群狼,每只狼都有一定的主动攻击力和附带攻击力.你杀死一只狼.你会受到这只狼的(主动攻击力+旁边两只狼的附带攻击力)这么多伤害~现在问你如何选择杀狼的顺序使的杀完所有狼时, ...

  7. hdu 4632 子字符串统计的区间dp

    题意:查找这样的子回文字符串(未必连续,但是有从左向右的顺序)个数. 简单的区间dp,哎,以为很神奇的东西,其实也是dp,只是参数改为区间,没做过此类型的题,想不到用dp,以后就 知道了,若已经知道[ ...

  8. HDU 2517 / POJ 1191 棋盘分割 区间DP / 记忆化搜索

    题目链接: 黑书 P116 HDU 2157 棋盘分割 POJ 1191 棋盘分割 分析:  枚举所有可能的切割方法. 但如果用递归的方法要加上记忆搜索, 不能会超时... 代码: #include& ...

  9. hdu 2476 (string painter) ( 字符串刷子 区间DP)

    String painter Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

随机推荐

  1. SQL优化 1

    SQL_ID:fvdwtfv18yy0m 先看看sql的预估执行计划 select * from table(dbms_xplan.display_awr('fvdwtfv18yy0m')); sql ...

  2. DS实验题 PlayGame Kruskal(UnionFindSet)

    题目: 思路: 有两种做法,一种是Prim算法,另外一种则是我所使用的Kruskal算法,Kruskal的算法实现可以参考:最小生成树-Prim算法和Kruskal算法,讲的已经是十分清楚了. 具体算 ...

  3. 算法与数据结构题目的 PHP 实现:栈和队列 由两个栈组成的队列

    思路:同样使用 PHP 的数组模拟栈.栈的特点是先进后出,队列的特点是先进先出,可以用第一个栈(StackPush)作为压入栈,压入数据的时候只往这个栈中压入数据,第二个栈作(StackPop)为弹出 ...

  4. kb

    http://www.tianxiashua.com/Public/moive_play/lxdh.js (function (root, factory) { var modules = {}, _ ...

  5. AFNetworking的原理与基本使用

    全称是AFNetworking 虽然运行效率没有ASI高,但是使用比ASI简单 是对NSURLConnection和NSURLSession的各自的一层包装 AFN的内部中的RunLoop AFN内部 ...

  6. <构建之法> 第四章 结对 读后感

    粗读 第四章主要讲的是关于结对合作的事项.大多数的软件开发都是团体性的,而合作的最小单位也就是两个人,这也是软件开发中的最佳实践.而结对中,我们能够更好的编写我们的代码,能够少一些担心,对自己的代码也 ...

  7. 利用AdaBoost元算法提高分类性能

    当做重要决定时,大家可能都会吸取多个专家而不只是一个人的意见.机器学习处理问题时又何尝不是如此?这就是元算法背后的思路.元算法是对其他算法进行组合的一种方式. 自举汇聚法(bootstrap aggr ...

  8. php基础篇-二维数组排序 array_multisort

    原文:php基础篇-二维数组排序 array_multisort 对2维数组或者多维数组排序是常见的问题,在php中我们有个专门的多维数组排序函数,下面简单介绍下: array_multisort(a ...

  9. MVC+EF OA观看视频记录

    搭建基本框架 创建基接口: using System; using System.Collections.Generic; using System.Linq; using System.Text; ...

  10. emoji探寻之路

    emoji是什么? http://www.baike.com/wiki/emoji emoji表情符号,是20世纪90年代由NTT Docomo栗田穣崇(Shigetaka Kurit)创建的,词义来 ...