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 ...
随机推荐
- 普冉PY32系列(四) PY32F002/003/030的时钟设置
目录 普冉PY32系列(一) PY32F0系列32位Cortex M0+ MCU简介 普冉PY32系列(二) Ubuntu GCC Toolchain和VSCode开发环境 普冉PY32系列(三) P ...
- C-02\规范及随机数rand()原理
小知识点 assert()函数 assert 断言函数,用于在调试过程中捕捉程序的错误.对某种假设条件进行检测,如果条件成立就不进行任何操作,如果条件不成立就捕捉到这种错误,并打印出错误信息,终止程序 ...
- STM32F4库函数初始化系列:串口发送
1 void Configuration(void) 2 { 3 USART_InitTypeDef USART_InitStructure; 4 GPIO_InitTypeDef GPIO_Init ...
- bat想要写一个卸载软件的脚本,最后宣布失败[未完待续...]
find 的用法:双引号,搜索内容是英文也要用双引号 C:\Users\clouder\Desktop\yanna>find '小智' products.txt FIND: 参数格式不正确 C: ...
- 与 Flutter 共创未来 | Flutter Forward 活动精彩回顾
作者 / Google 开发者框架和语言 (含 Flutter.Dart 和 Go) 产品经理 & 用户体验总监 Tim Sneath 我们很高兴可以在 Flutter Forward 活动 ...
- 我用ChatGPT做直播技术选型,卷死了同事
摘要 近两年即时通讯/直播产品炙手可热,市场上针对ToB的产品日益增多,企业该如何去选型呢?本文分享了笔者对于直播产品的思考,将从直播SDK实例功能特性.常见业务场景.注意事项及最佳实践等方面介绍如何 ...
- CF1781D 解题乱弹
abc1057510554 老师说,搞这种数论题,就可以在 CF 上 number theory 板刷一个 1300-1900 就可以了. 然后发现连 1800 的题都做不出来,我可以退役力 QAQ ...
- 解决Revit导出FBX模型材质丢失的问题
初次使用Revit导出fbx格式模型,在导出模型后发现模型材质丢失了,上网查询之后也没到具体原因是什么,不过倒是找到了解决方式:在Revit中安装naviswork插件,然后从revit中导出nwc格 ...
- MyBatis 查询的条目与预期的不一致
预期查询的数据条目是 4 条: 但是 MyBatis 查询出来的结果只有 2 条数据: resultMap 开启了 autoMapping 功能,就不需要多余地添加 result.下面是错误的映射操作 ...
- tp-link路由器后台_硬解
title: 脚本_tp-link路由器后台_硬解 author: 杨晓东 permalink: 脚本 date: 2021-10-02 11:27:04 categories: - 投篮 tags: ...