题目:

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

题解

区间dp····用f[i][j]表示我们在只考虑让i到j个人上场的情况下能获得的最小不高兴值···,然后我们考虑让第i个人在第几个上场··枚举i到j中的k,考虑让第i人再第k个人之后上场··那么第i个人就是第i-k+1个上场的··对答案贡献是(i-k)*num[i],另外k+1到j个人也会对答案有新的贡献,为(i-k+1)*sum[k+1——j]

代码

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<cctype>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
const int inf=0x3f3f3f3f;
int num[N],sum[N],f[N][N],T,n;
inline int R()
{
char c;int f=;
for(c=getchar();c<''||c>'';c=getchar());
for(;c<=''&&c>='';c=getchar()) f=(f<<)+(f<<)+c-'';
return f;
}
int main()
{
// freopen("a.in","r",stdin);
T=R();
for(int t=;t<=T;t++)
{
n=R();
memset(sum,,sizeof(sum));
for(int i=;i<=n;i++) num[i]=R(),sum[i]=sum[i-]+num[i];
memset(f,,sizeof(f));
for(int i=;i<=n;i++)
for(int j=i+;j<=n;j++) f[i][j]=inf;
for(int i=n-;i>=;i--)
for(int j=i+;j<=n;j++)
for(int k=i;k<=j;k++)
f[i][j]=min(f[i][j],f[i+][k]+f[k+][j]+(k-i+)*(sum[j]-sum[k])+num[i]*(k-i));
printf("Case #%d: %d\n",t,f[][n]);
}
return ;
}

刷题总结——you are the one(hdu4283)的更多相关文章

  1. LeetCode刷题系列

    LeetCode 我们工作面试和提高自身数据结构和算法能力的时候往往需要刷刷题,我选择LeetCode是通过一个留学论坛了解的.专业,覆盖语种全面. 提前说说刷题的心得: 尽量手写代码,少使用IDE的 ...

  2. ife任务刷题总结(一)-css reset与清除浮动

    本文同时发布于本人的个人网站www.yaoxiaowen.com 百度创办的前端技术学院,是一个面向大学生的前端技术学习平台.虽然只有大学生才有资格报名,提交代码进行比赛排名.但是这并不妨碍我们这些初 ...

  3. 刷题ING...

    我用codeVS刷题.. 努力准备!!

  4. XidianOJ 1020 ACMer去刷题吧

    题目描述 刷题是每个ACMer必由之路,已知某oj上有n个题目,第i个题目小X能做对的概率为Pi(0<=Pi<=1,1<=i<=n) 求小X至少做对k道题的概率 输入 第一行输 ...

  5. 【BZOJ-4590】自动刷题机 二分 + 判定

    4590: [Shoi2015]自动刷题机 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 156  Solved: 63[Submit][Status ...

  6. NOI题库分治算法刷题记录

    今天晚自习机房刷题,有一道题最终WA掉两组,极其不爽,晚上回家补完作业欣然搞定它,特意来写篇博文来记录下 (最想吐槽的是这个叫做分治的分类,里面的题目真的需要分治吗...) 先来说下分治法 分治法的设 ...

  7. NOI题库刷题日志 (贪心篇题解)

    这段时间在NOI题库上刷了刷题,来写点心得和题解 一.寻找平面上的极大点 2704:寻找平面上的极大点 总时间限制:  1000ms  内存限制:  65536kB 描述 在一个平面上,如果有两个点( ...

  8. 用js刷题的一些坑

    leecode可以用js刷题了,我大js越来越被认可了是吧.但是刷题中会因为忽略js的一些特性掉入坑里.我这里总结一下我掉过的坑. 坑1:js中数组对象是引用对象 js中除了object还有数组对象也 ...

  9. BZOJ4590 自动刷题机

    Description 曾经发明了信号增幅仪的发明家SHTSC又公开了他的新发明:自动刷题机--一种可以自动AC题目的神秘装置.自动 刷题机刷题的方式非常简单:首先会瞬间得出题目的正确做法,然后开始写 ...

  10. PE刷题记录

    PE刷题记录 PE60 / 20%dif 这道题比较坑爹. 所有可以相连的素数可以构成一张图,建出这张图,在其中找它的大小为5的团.注意上界的估算,大概在1W以内.1W内有1229个素数,处理出这些素 ...

随机推荐

  1. 如何从Ubuntu 16.04 LTS升级到Ubuntu 18.04 LTS

    可以说非常简单(假设过程顺利!!) 您只需打开Software&Update,进入"Updates"选项卡,然后从“有新版本时通知我”下拉菜单中选择“适用长期支持版”选项. ...

  2. Python封装补充

    property属性 property实际是setter getter deleter是集合体,并不是一个单独的方法 import math # 使用的库 class Circle: def __in ...

  3. mysql中的空值问题

    MySQL的查询如果需要用到空值的情况下,where后面的条件就需要注意了 MySQL中的表示空值的方法:is null 和 is not null 比如:select * from user whe ...

  4. cocos2d-x中的字符串操作

    1:循环体中字符串的构造.      通常用于多个有规律的文件的名字,诸如:[NSString stringWithFormat:@"filed.png",i].我们可以通过spr ...

  5. 【动态规划】bzoj1939: [Croatian2010] Zuma

    隐约记得类似的一道JSOI祖玛……然后好像这题不能够把珠子合并成一段?或许是因为这里珠子碰在一起之后可以不消除? Description 有一行 N 个弹子,每一个都有一个颜色.每次可以让超过 K 个 ...

  6. 笔记--Day2--python基础2

    一.鸡汤 1.提高自我修养 2.人丑就要多读书 3.多走走,开拓眼界 二.目录: 1.列表.元组操作 2.字符串操作 3.字典操作 dict是无序的 key必须是唯一的 4.集合操作 集合是一个无序的 ...

  7. python入门:while 循环的基本用法

    #!/usr/bin/env python # -*- coding:utf-8 -*- #while 循环的作用 import time while True: ") time.sleep ...

  8. 22.Yii2.0框架多表关联一对一查询之hasOne

    思路: 通过文章查它对应的分类信息 一对一的关系 控制器里 //一对一关联查询 public function actionRelatesone() { //方法一,hasOne() 用查一条文章的结 ...

  9. python-数据类型总结 (面试常问)

    目录 数字类型总结 拷贝 浅拷贝 深拷贝 数字类型总结 一个值 多个值 整型/浮点型/字符串 列表/字典/元祖/集合 有序 无序 字符串/列表/元祖 字典/集合 可变 不可变 列表/字典/集合 整型/ ...

  10. JAVA基础篇—模拟服务器与客户端通信

    第一种: 客户端class Client package 服务器发送到客户端; import java.io.BufferedReader; import java.io.InputStreamRea ...