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. Kali Linux Web 渗透测试秘籍 中文版

    第一章 配置 Kali Linux 简介 在第一章中,我们会涉及如何准备我们的 Kali 以便能够遵循这本书中的秘籍,并使用虚拟机建立带有存在漏洞的 Web 应用的实验室. 1.1 升级和更新 Kal ...

  2. DIVFusion_ Darkness-free infrared and visible image fusion 论文解读

    研究 背景: ​ 当前图像融合方法都是针对正常照明的红外与可见光图像设计的,无法有效处理夜景下的情况. ​ 而针对夜景下的融合可以分为以下两个步骤,1 可见光图像增强,2 可见光图像与红外图像融合.但 ...

  3. 下篇 | 使用 🤗 Transformers 进行概率时间序列预测

    在<使用 Transformers 进行概率时间序列预测>的第一部分里,我们为大家介绍了传统时间序列预测和基于 Transformers 的方法,也一步步准备好了训练所需的数据集并定义了环 ...

  4. php中 mysql 中文乱码解决办法

     首先要保证是utf-8编码或者支持中文的编码 2.Windows下修改方法 MySQL安装目录下的my-default.ini改为my.ini文件 [client]节点 default-charac ...

  5. keep-alive详解

    1.什么是keep-alive? keep-alive 是 Vue 的内置组件,当它包裹动态组件时,会缓存不活动的组件实例,而不是销毁它们.keep-alive 是一个抽象组件:它自身不会渲染成一个 ...

  6. net core 依赖注入DI

    控制反转:Inversion Of Control,简称 IOC,是面向对象中的一种设计原则,调用者不自己new实例,而是交给容器去创建,可以减轻代码的耦合度. 依赖注入:Dependency Inj ...

  7. centos7 开机自启动脚本

    两种实现方式 方法1:(rc.local) 1.因为在centos中/etc/rc.d/rc.local的权限被降低了,所以需要赋予其可执行权 chmod +x /etc/rc.d/rc.local ...

  8. eclipse项目转idea项目

    背景:用习惯了idea再去用eclipse实在用的不习惯,于是将老的eclipse项目导入到eclipse,网上有很多教程,看了很多博客都不行,一直报错,各种报错,现在终于好了,我们一起来看看怎么将e ...

  9. kubebuilder简明教程

    一.operator概述 Operator 是 Kubernetes 的扩展软件,它利用 定制资源 管理应用及其组件. Operator 遵循 Kubernetes 的理念,特别是在控制器 方面[1] ...

  10. [NPUCTF2020]EzRSA

    [NPUCTF2020]EzRSA 题目: from gmpy2 import lcm , powmod , invert , gcd , mpz from Crypto.Util.number im ...