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. Trie树

    一.什么是trie树 1.Trie树 (特例结构树)   Trie树,又称单词查找树.字典树,是一种树形结构,是一种哈希树的变种,是一种用于快速检索的多叉树结构.典型应用是用于统计和排序大量的字符串( ...

  2. Codeforces Round #378 (Div. 2) C D

    在实验室通宵 一边做水题一边准备随时躲起来以免被门卫大爷巡查发现..结果居然没来.. 本来以为可以加几分变个颜色..结果挂了CD...状态有点差...思维不太活跃 沉迷暴力不能自拔 D 给出n个长方体 ...

  3. [转]C++11 多线程

    转载自:http://www.cnblogs.com/zhuyp1015/archive/2012/04/08/2438288.html C++11开始支持多线程编程,之前多线程编程都需要系统的支持, ...

  4. github 或者gitlab 设置添加SSH, 避免每次提交重复输入用户名

    克隆项目二种方式: 1. 使用https url克隆,   复制https url 然后到 git clone https-url 2.使用 SSH url 克隆却需要在克隆之前先配置和添加好 SSH ...

  5. (copy) Shell Script to Check Linux System Health

    source: http://linoxide.com/linux-shell-script/shell-script-check-linux-system-health/ This article ...

  6. tomcat access log 参数

    %a - 客户端IP地址 %A - 本机IP地址 %b - 发送字节数,不含HTTP头 如果为空是  '-' %B - 同上 %h - 客户端机器名 (如果connector的enableLookup ...

  7. csuoj 1507: 超大型LED显示屏

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1507 1507: 超大型LED显示屏 时间限制: 1 Sec  内存限制: 128 MB 提交:  ...

  8. ACM Coder [T1002] 一直wrong answer,不知道为什么。上代码!就对就对!

    忘了改了什么,后来居然对了!做打不死的菜鸟! #include <stdio.h> #include <stdbool.h> #define arrayLength 20 #d ...

  9. C# 获取sql数据库表列名,及列名说明备注信息

    获取指定表列名及备注: select * from syscolumns where id=object_id(N'表名') SELECT a.name [column], b.name type, ...

  10. 更新数据前jquery如何填充数据到表单域中

    $("#p_city option[value='${project.city}']").attr("selected","selected" ...