刷题总结——you are the one(hdu4283)
题目:
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)的更多相关文章
- LeetCode刷题系列
LeetCode 我们工作面试和提高自身数据结构和算法能力的时候往往需要刷刷题,我选择LeetCode是通过一个留学论坛了解的.专业,覆盖语种全面. 提前说说刷题的心得: 尽量手写代码,少使用IDE的 ...
- ife任务刷题总结(一)-css reset与清除浮动
本文同时发布于本人的个人网站www.yaoxiaowen.com 百度创办的前端技术学院,是一个面向大学生的前端技术学习平台.虽然只有大学生才有资格报名,提交代码进行比赛排名.但是这并不妨碍我们这些初 ...
- 刷题ING...
我用codeVS刷题.. 努力准备!!
- XidianOJ 1020 ACMer去刷题吧
题目描述 刷题是每个ACMer必由之路,已知某oj上有n个题目,第i个题目小X能做对的概率为Pi(0<=Pi<=1,1<=i<=n) 求小X至少做对k道题的概率 输入 第一行输 ...
- 【BZOJ-4590】自动刷题机 二分 + 判定
4590: [Shoi2015]自动刷题机 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 156 Solved: 63[Submit][Status ...
- NOI题库分治算法刷题记录
今天晚自习机房刷题,有一道题最终WA掉两组,极其不爽,晚上回家补完作业欣然搞定它,特意来写篇博文来记录下 (最想吐槽的是这个叫做分治的分类,里面的题目真的需要分治吗...) 先来说下分治法 分治法的设 ...
- NOI题库刷题日志 (贪心篇题解)
这段时间在NOI题库上刷了刷题,来写点心得和题解 一.寻找平面上的极大点 2704:寻找平面上的极大点 总时间限制: 1000ms 内存限制: 65536kB 描述 在一个平面上,如果有两个点( ...
- 用js刷题的一些坑
leecode可以用js刷题了,我大js越来越被认可了是吧.但是刷题中会因为忽略js的一些特性掉入坑里.我这里总结一下我掉过的坑. 坑1:js中数组对象是引用对象 js中除了object还有数组对象也 ...
- BZOJ4590 自动刷题机
Description 曾经发明了信号增幅仪的发明家SHTSC又公开了他的新发明:自动刷题机--一种可以自动AC题目的神秘装置.自动 刷题机刷题的方式非常简单:首先会瞬间得出题目的正确做法,然后开始写 ...
- PE刷题记录
PE刷题记录 PE60 / 20%dif 这道题比较坑爹. 所有可以相连的素数可以构成一张图,建出这张图,在其中找它的大小为5的团.注意上界的估算,大概在1W以内.1W内有1229个素数,处理出这些素 ...
随机推荐
- HTML_3
html列表 有序列表:在网页上定义一个有编号的内容列表可以用<ol>.<li>配合使用来实现,在网页上生成的列表,每条项目上按1.2.3编号,有序列表在实际开发中较少使用.代 ...
- MySQL索引类型及优化
索引是快速搜索的关键.MySQL索引的建立对于MySQL的高效运行是很重要的.下面介绍几种常见的MySQL索引类型. 在数据库表中,对字段建立索引可以大大提高查询速度.假如我们创建了一个 mytabl ...
- IOS版本判断
-(void)getIOSVersion { //#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 50000 //此方法和编译器相关 //quanju.iOS ...
- 性能优化之MySQL优化(慕课)
MySQL数据库优化 1-1MySQL优化简介 数据库优化的目的 避免出现页面访问错误 由于数据库连接timeout产生5XX错误 由于慢查询造成页面无法加载 由于阻塞造成数据无法提交 增加数据库的稳 ...
- Java微信公众号开发----关键字自动回复消息
在配置好开发者配置后,本人第一个想要实现的是自动回复消息的功能,说明以下几点: 1. url 仍然不变,还是开发配置里的url 2. 微信采用 xml 格式传输数据 3.微信服务器传给我们的参数主要有 ...
- CentOS7下systemd
配置文件: /usr/lib/systemd/system:每个服务最主要的启动脚本设置,类似于之前的/etc/init.d/ /run/systemd/system:系统执行过程中所产生的服务脚本, ...
- Win10家庭版找不到组策略gpedit.msc
首先在桌面上建立一个txt文本文件,将下面的代码复制到里面 @echo off pushd "%~dp0" dir /b C:\Windows\servicing\Packages ...
- LNMP的环境搭建
新装的Linux 机器,还没有来得及安装网站环境,这篇文章就是记录一下自己安装LNMP的一般步骤. 之前在Laravel视频中看过这段的讲解,后来也试着安装过,基本的命令不算是熟练掌握,所以还要看看之 ...
- IE浏览器缓存问题解决方法(非常严重)
IE浏览器缓存问题解决方法整理 一.IE浏览器缓存的内容分析: IE浏览器会缓存网页中的GET和XHR的内容,并且在IE浏览器中如果请求方式是get方式的话,IE浏览器会进行识别,如果该get请求的u ...
- laravel5 使用try catch
在laravel5中使用以下代码并没有捕获异常 try{ var_dump($val); }catch (Exception $e){ var_dump($e); } Laravel 5 时代控制器 ...