hdu 4283You 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?
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
代码
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std; const int INF = 0x3f3f3f;
int n, num[105], dp[105][105], sum[105]; int main()
{
int t, cnt;
cin >> t;
while (t--)
{
scanf("%d", &n);
memset(dp, 0, sizeof dp); for (int i = 1; i <= n; i++)
{
scanf("%d", &num[i]);
}
sum[0] = 0;
for (int i = 1; i <= n; i++)
{
sum[i] = sum[i - 1] + num[i];
}
for (int i = 1; i <= n; i++)
{
for (int j = i + 1; j <= n; j++)
dp[i][j] = INF;
}
for (int i = n; i >= 1; i--)
{
for (int j = i + 1; j <= n; j++)
{
for (int k = 1; k <= j - i + 1; k++)
{
dp[i][j] = min(dp[i][j], dp[i + 1][i + k - 1] + num[i] * (k - 1) + dp[i + k][j] + k*(sum[j] - sum[i + k - 1]));
}
}
}
printf("Case #%d: %d\n", cnt++, dp[1][n]);
}
system("pause");
return 0;
}
hdu 4283You Are the One的更多相关文章
- 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 ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 3791二叉搜索树解题(解题报告)
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...
- hdu 4329
problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟 a. p(r)= R'/i rel(r)=(1||0) R ...
随机推荐
- Nginx09 http的keepalive及在nginx的配置使用
1 为什么要有Connection: keep-alive? 在早期的HTTP/1.0中,每次http请求都要创建一个连接,而创建连接的过程需要消耗资源和时间,为了减少资源消耗,缩短响应时间,就需要重 ...
- Adobe GENP2019~2022 for Win 一键激活
Adobe GENP2019~2022 for Win 一键激活 一.简介 GenP是一个由国外团队开发的Adobe Win全系列软件激活工具,专门在Win系统上激活所有Adobe软件的2019和20 ...
- Channel和Stream的单双向问题
stream分为input和output,为单向. channel为双向,可以write也可以read,但是通过inputstream或者outputstream获取的channle并不能实现双向的数 ...
- 了解舵机以及MG996R的控制方法
了解舵机以及MG996R的控制方法 1.舵机基础知识: 舵机是遥控航空.航天模型控制动作,改变方向的重要组成部件,舵机是一种位置(角度)伺服的驱动器. 舵机主要适用于那些需要角度不断变化并可以保持的控 ...
- IDEA插件Apifox,一键自动生成接口文档!
有关Apifox软件之前写过一篇文章: 接口测试神器Apifox,亲测好用! 如何一键自动生成数据库文档之前也写过一篇文章: 数据库界的Swagger:一键生成数据库文档! 一.Apifox插件的优势 ...
- Python爬虫:原来微博上的视频下载链接在这啊
最近看了一下网页版的微博,觉得那上面的视频不错,想获取它上面的下载链接,于是就写了这篇博文. 1. 几个视频播放平台的下载链接的实现 1. 西瓜视频 西瓜视频这个平台上面的视频下载链接一开始就存在于视 ...
- SqlServer取分组第一条数据
SELECT * FROM (SELECT t.*, RANK() OVER (PARTITION BY t.a ORDER BY t.b DESC) AS drank FROM table1 t) ...
- html+css+js思维导图
- unity通过隐藏layer隐藏组件
设置组件layer 修改组件layer为需要隐藏的layer 隐藏组件 修改layer为隐藏状态 CenterCam.GetComponent<Camera>().cullingMask ...
- java学习日记20230228-数据类型及加号运算
程序中+使用: 1.两侧是数值型,则相加: 2.一方为字符串,则拼接: 3.运算顺序从做到右: 数据类型 每一种数据都定义了明确的数据类型,在内存中分配了不同大小的内存空间: java数据类型 基本数 ...