You Are the One

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

Submit Status

Description

  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
 

Sample Output

Case #1: 20
Case #2: 24
 
 
 
 
 #include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
#define inf 10000000000LL
long long dp[][]; int main()
{
freopen("in.txt","r",stdin);
long long t,n,i,j,a[],sum[],k,cas=;
scanf("%I64d",&t);
while(t--)
{
sum[]=;
scanf("%I64d",&n);
for(i=; i<=n; i++)
scanf("%I64d",&a[i]),sum[i]=sum[i-]+a[i];
for(i=; i<=n; i++)
for(j=i; j<=n; j++)if(i!=j)dp[i][j]=inf;
else dp[i][j]=;
int l=;
while(l<n)
{
for(i=;i+l<=n;i++)
{
dp[i][i+l]=min(dp[i][i+l],dp[i+][i+l]+sum[i+l]-sum[i]);
dp[i][i+l]=min(dp[i][i+l],dp[i+][i+l]+a[i]*l);
for(k=;k<l;k++)
dp[i][i+l]=min(dp[i][i+l],dp[i+][i+k]+dp[i+k+][i+l]+a[i]*k+(k+)*(sum[i+l]-sum[i+k]));
}
l++;
}
cout<<"Case #"<<cas++<<": ";
cout<<dp[][n]<<endl;
}
}
 
 

You Are the One DP的更多相关文章

  1. BZOJ 1911: [Apio2010]特别行动队 [斜率优化DP]

    1911: [Apio2010]特别行动队 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 4142  Solved: 1964[Submit][Statu ...

  2. 2013 Asia Changsha Regional Contest---Josephina and RPG(DP)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4800 Problem Description A role-playing game (RPG and ...

  3. AEAI DP V3.7.0 发布,开源综合应用开发平台

    1  升级说明 AEAI DP 3.7版本是AEAI DP一个里程碑版本,基于JDK1.7开发,在本版本中新增支持Rest服务开发机制(默认支持WebService服务开发机制),且支持WS服务.RS ...

  4. AEAI DP V3.6.0 升级说明,开源综合应用开发平台

    AEAI DP综合应用开发平台是一款扩展开发工具,专门用于开发MIS类的Java Web应用,本次发版的AEAI DP_v3.6.0版本为AEAI DP _v3.5.0版本的升级版本,该产品现已开源并 ...

  5. BZOJ 1597: [Usaco2008 Mar]土地购买 [斜率优化DP]

    1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4026  Solved: 1473[Submit] ...

  6. [斜率优化DP]【学习笔记】【更新中】

    参考资料: 1.元旦集训的课件已经很好了 http://files.cnblogs.com/files/candy99/dp.pdf 2.http://www.cnblogs.com/MashiroS ...

  7. BZOJ 1010: [HNOI2008]玩具装箱toy [DP 斜率优化]

    1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 9812  Solved: 3978[Submit][St ...

  8. px、dp和sp,这些单位有什么区别?

    DP 这个是最常用但也最难理解的尺寸单位.它与“像素密度”密切相关,所以 首先我们解释一下什么是像素密度.假设有一部手机,屏幕的物理尺寸为1.5英寸x2英寸,屏幕分辨率为240x320,则我们可以计算 ...

  9. android px转换为dip/dp

    /** * 根据手机的分辨率从 dp 的单位 转成为 px(像素) */ public int dipTopx(Context context, float dpValue) { final floa ...

  10. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

随机推荐

  1. Linux-mount命令和umount命令 (8)

    mount:用于挂载文件系统,使能访问其它文件系统中的资源 umount:用于卸载已挂载的文件系统 mount: 格式: mount [-参数] [设备名称] [挂载点] 其中常用的参数(参数默认自带 ...

  2. tkinter第二章(添加图片,背景图片)

    #插入文件图片import tkinter as tk root = tk.Tk() #创建一个标签类, [justify]:对齐方式textLabel = tk.Label(root,text=&q ...

  3. mpls vpn剩余笔记

    将IP地址映射为简单的具有固定长度的标签 用于快速数据包交换 20 3 1 8 在整个转发过程中,交换节点仅根据标记进行转发 标签交换路径(LSP) 多协议标签交换MPLS最初是为了提高转发速度而提出 ...

  4. 吐槽下微软的vs code编辑器

    缺点:不能同时打开多个文件夹(打开多个文件夹得先ctrl+shift+N窗口或者除非你的所有项目文件都在同一个文件夹目录下) 优点是支持用户设置以及提供很多插件 // 将设置放入此文件中以覆盖默认设置 ...

  5. 【转】为什么选择Spring Boot作为微服务的入门级微框架

    本文为普元云计算高级工程师许二虎在普元云计算架构设计群的微课堂分享.如需加入普元新一代数字化企业云平台研发设计群参与微课堂.架构设计与讨论直播,请直接回复此公众号:"加群 姓名 公司 职位 ...

  6. 九度OJ 1010 A +B

    #include <iostream> #include <string> #include <sstream> using namespace std; int ...

  7. 结对编程1--基于GUI的四则运算题目生成器

    最终项目详细代码(coding地址)/李志强的博客/我的详细代码/方言的博客 一.需求分析 1.实现之前项目的功能,如:除了整数之外,还要支持真分数的四则运算,真分数的运算,并且要求能处理用户的输入, ...

  8. 个人作业1——四则运算题目生成程序(基于C++)

    题目描述: 从<构建之法>第一章的 "程序" 例子出发,像阿超那样,花二十分钟写一个能自动生成小学四则运算题目的命令行 "软件",满足以下需求: 1 ...

  9. 团队作业8——第二次项目冲刺(Beta阶段)5.18

    1.当天站立式会议照片 会议内容: 本次会议为第一次会议 本次会议在陆大楼2楼召开,本次会议内容: ①:部署第二次敏捷冲刺的计划 ②:做第一天任务的详细分工 ③:规定完成时间是在第二天之前 ④:遇到困 ...

  10. 201521123075 《Java程序设计》第4周学习总结

    1. 本周学习总结 1.1 尝试使用思维导图总结有关继承的知识点. 1.2 使用常规方法总结其他上课内容. - 了解了多态就是以单一的接口操作多种类型的对象,但是对多态和继承的关系还是有点混乱. - ...