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. Groovy Script in SoapUI REST Testing

    1. Run special step: testRunner.runTestStepByName("stepName/requestName") get it's respons ...

  2. python环境搭建和打包

    安装: python是有两个版本的一个是2.x,一个是3.x,这两个版本是不兼容的所有请使用前看准版本.下面我们主要说3.5版本. Mac:https://www.python.org/ftp/pyt ...

  3. 开源分享 Unity3d客户端与C#分布式服务端游戏框架

    很久之前,在博客园写了一篇文章,<分布式网游server的一些想法语言和平台的选择>,当时就有了用C#做网游服务端的想法.写了个Unity3d客户端分布式服务端框架,最近发布了1.0版本, ...

  4. 快速排序/快速查找(第k个, 前k个问题)

    //快速排序:Partition分割函数,三数中值分割 bool g_bInvalidInput = false; int median3(int* data, int start, int end) ...

  5. python利用urllib实现的爬取京东网站商品图片的爬虫

    本例程使用urlib实现的,基于python2.7版本,采用beautifulsoup进行网页分析,没有第三方库的应该安装上之后才能运行,我用的IDE是pycharm,闲话少说,直接上代码! # -* ...

  6. 说说 DWRUtil

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp27 说说 DWRUtil 比如我们从服务器端获得了一个citylist的数 ...

  7. 【转】Spring AOP 实现之CGLIB

    详见: http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp91    cglib(Code Generation Library)是 ...

  8. 团队作业8——第二次项目冲刺(Beta阶段)--5.24 forth day

    团队作业8--第二次项目冲刺(Beta阶段)--5.24 forth day Day four: 会议照片 项目进展 Beta冲刺的第四天,以下是今天具体任务安排: 队员 昨天已完成的任务 今日计划完 ...

  9. Java计算器1.0版

    此版本只是设计了页面,还没有实现事件监听   代码: package com.niit.javagui; import java.awt.Button; import java.awt.FlowLay ...

  10. Java 第三周总结

    1.本周学习总结 2.书面作业 1.代码阅读 public class Test1 { private int i = 1;//这行不能修改 private static int j = 2; pub ...