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的更多相关文章

  1. 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 ...

  2. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  3. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  4. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  5. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  6. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  7. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  8. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  9. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

  10. hdu 4329

    problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟  a.     p(r)=   R'/i   rel(r)=(1||0)  R ...

随机推荐

  1. JAVA虚拟机08--垃圾回收--HotSpot的算法实现细节

    1 stop the world 2 减少stop the world的时间-OopMap 3 OopMap数据结构的维护-安全点-安全区域 3.1安全点 3.2在垃圾回收时如何让所有线程到达最近的安 ...

  2. Unreal 各种指针类型是怎么回事

    引言 读完本篇文章,你会了解为何UE中C++作为其开发语言,使用的指针,为何各式各样. 你需要对UE有所了解,如果不了解也没关系,也可以看下这篇文章,就当了解一下最复杂的应用的系统指针设计是如何. 可 ...

  3. Zstack使用经验系列2-安装的存储配置

    从上图读者应该能看出当初分配主存储和镜像存储时空间分配的是多么不合理,镜像空间不需要那么多.不过这时系统已经运行了近1年,很多云主机以及系统服务都搭好了,如果再重新分配空间是多么的麻烦! 所以开始为p ...

  4. 微信小程序组件封装传值以及问题点规避

    封装组件 1.在components文件加下新建组件文件夹,在该文件夹下新建组件 2.在app.json中注册该组件 "usingComponents": { "page ...

  5. 网页怎样引入本地硬盘上的JS文档

    网页通过<script>标记可以引入在线的js文档,只有把网页保存在本地硬盘才能使用相对路径引入本地js文档,普通浏览器难以实现在线页面上引入本地js文档.怎么解决这个问题呢? 首先准备好 ...

  6. 有趣的python库-MyQR

    MyQR-个性二维码 基本使用 from MyQR import myqr import os myqr.run( words="hu qing nian ni zhen bang, you ...

  7. JZOJ 2022.07.18【提高组A】模拟

    \(\text{T1}\) 很容易想到用 \(f_1 f_2 ... f_k\) 来表示第 \(n\) 项 发现重点关注指数即可,即我们要递推 \(f_1 ... f_k\) 对应的指数 递推涉及 \ ...

  8. 跳板攻击之:CS代理转发

    跳板攻击之:CS代理转发 目录 跳板攻击之:CS代理转发 1 环境准备 1.1 环境拓扑 1.2 前提 2 配置 Socks 代理 3 配置转发监听器(正向连接) 4 配置转发上线(反向连接) 1 环 ...

  9. 化学式latex语法

    $2 CO_2 \stackrel{光}{\underset{\text{催化剂}}{\longrightarrow}}2 Fe + 3 CO_2$ $\ce{CO2}$ $\ce{CU2+}$ $\ ...

  10. Oracle 11g 单机服务器ASM部署

    Oracle oracle,相比都有所了解,是一家企业级的数据库公司(收费),上图是oracle官网,也是对外的服务平台 oracle有自己独特的安装方式:ASM   :  自动存储管理(ASM,Au ...