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. 力扣每日一题2023.1.19---2299. 强密码检验器 II

    如果一个密码满足以下所有条件,我们称它是一个 强 密码:    它有至少 8 个字符.    至少包含 一个小写英文 字母.    至少包含 一个大写英文 字母.    至少包含 一个数字 .    ...

  2. Vue 24 props

    1 简介 props主要用于组件的传值,他的工作就是为了接收外面传过来的数据,与data.el.ref是一个级别的配置项 2 一个简单示例 1)StudentComp.vue <template ...

  3. P13_协同工作_小程序权限管理的概念以及成员管理的两个方面

    协同工作和发布 - 协同工作 了解权限管理需求 在中大型的公司里,人员的分工非常仔细:同一个小程序项目,一般会有不同岗位.不同角色的员工同时参与设计与开发. 此时出于管理需要,我们迫切需要对不同岗位. ...

  4. JavaScript字符串的常用方法

    一.操作方法 我们也可将字符串常用的操作方法归纳为增.删.改.查,需要知道字符串的特点是一旦创建了,就不可变 增 这里增的意思并不是说直接增添内容,而是创建字符串的一个副本,再进行操作 除了常用+以及 ...

  5. Cesium viewer.extend 五个拓展(五)

    2023-01-09 1.viewerDragDropMixin 一个mixin,它为查看器小部件添加了对CZML文件的默认拖放支持. czml即为json,但json不一定为czml:如同geojs ...

  6. [Ynoi2016] 掉进兔子洞

    \(\text{Solution}\) 莫队配合 \(\text{bitset}\) 发现答案困难的部分在于同一个数在三个区间出现次数的最小值 考虑强行拆开看,用莫队处理出每个区间每个数的出现次数,这 ...

  7. JZOJ 3167.查税

    \(\text{Solution}\) 记 \(k\) 这个办公室相关属性有 \(t,z,s\) 对于以后的某一天 \(T\),其账户余额为 \((T-t)z+s\) 要最大化这东西,不妨另 \(b= ...

  8. JZOJ 【2020.11.30提高组模拟】剪辣椒(chilli)

    题目大意 给出一棵 \(n\) 个节点的树,删去其中两条边 使得分出的三个子树大小中最大与最小的差最小 分析 先一边 \(dfs\) 预处理出以 \(1\) 为根每个点的 \(size\) 然后按 \ ...

  9. Hexo系列(一):Hexo简介

    作者:独笔孤行 官网:​​ ​http://anyamaze.com​​ 公众号:云实战 前言 博客网站的实现方法有很多种,常用的博客框架主要有wordpress.Z-Blog.hexo.Typech ...

  10. 使用flex布局(多行,一行三个),换行后最后一行左右对齐问题

    <html> <head> <style> html, body, ul { margin: 0; padding: 0; } ul { width: 100%; ...