hdu 4283 You Are the One 区间dp
You Are the One
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
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?
The next n line are n integer D1-Dn means the value of diaosi of boys (0 <= Di <= 100)
5
1
2
3
4
5
5
5
4
3
2
2
Case #2: 24
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = ,inf=1e9+;
int a[N],pre[N];
int dp[N][N];
int main()
{
int T,cas=;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
pre[i]=pre[i-]+a[i];
}
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)
{
for(int j=i;j<=n;j++)
dp[i][j]=inf;
}
for(int i=;i<=n;i++)
{
for(int j=;j+i-<=n;j++)
{
int st=j;
int en=j+i-;
for(int k=st;k<=en;k++)
{
int p=k-st+;
dp[st][en]=min(dp[st][en],dp[st+][k]+dp[k+][en]+p*a[st]+(pre[en]-pre[k])*p);
}
}
}
printf("Case #%d: %d\n",cas++,dp[][n]-(pre[n]));
}
return ;
}
/*
2
5
1 2 3 4 5
5
5 4 3 2 2
*/
hdu 4283 You Are the One 区间dp的更多相关文章
- hdu 4283"You Are the One"(区间DP)
传送门 https://www.cnblogs.com/violet-acmer/p/9852294.html 题意: 有n个屌丝排成一排,每个屌丝都有一个不开心值a[ i ]( i=1,2,3,.. ...
- HDU 4283 You Are the One ——区间dp
参考了许多大佬 尤其是https://blog.csdn.net/woshi250hua/article/details/7973824这一篇 ,最后我再加一点我的见解. 大意是 给定一个序列,序列 ...
- HDU 4283 (第k个出场 区间DP)
http://blog.csdn.net/acm_cxlove/article/details/7964594 http://www.tuicool.com/articles/jyaQ7n http: ...
- 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 ...
- HDU 5900 QSC and Master (区间DP)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5900 题意:给出序列$A_{i}.key$和$A_{i}.value$,若当前相邻的两个数$A_{ ...
- HDU 5115 (杀狼,区间DP)
题意:你是一个战士现在面对,一群狼,每只狼都有一定的主动攻击力和附带攻击力.你杀死一只狼.你会受到这只狼的(主动攻击力+旁边两只狼的附带攻击力)这么多伤害~现在问你如何选择杀狼的顺序使的杀完所有狼时, ...
- hdu 4632 子字符串统计的区间dp
题意:查找这样的子回文字符串(未必连续,但是有从左向右的顺序)个数. 简单的区间dp,哎,以为很神奇的东西,其实也是dp,只是参数改为区间,没做过此类型的题,想不到用dp,以后就 知道了,若已经知道[ ...
- HDU 2517 / POJ 1191 棋盘分割 区间DP / 记忆化搜索
题目链接: 黑书 P116 HDU 2157 棋盘分割 POJ 1191 棋盘分割 分析: 枚举所有可能的切割方法. 但如果用递归的方法要加上记忆搜索, 不能会超时... 代码: #include& ...
- hdu 2476 (string painter) ( 字符串刷子 区间DP)
String painter Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
随机推荐
- 【iCore3 双核心板_FPGA】实验十四:FSMC总线通信实验——独立地址模式
实验指导书及代码包下载: http://pan.baidu.com/s/1kVJBxJ5 iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...
- 安装Arch Linux
参考自:https://wiki.archlinux.org/index.php/Main_Page_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87) 用fdisk建立分区 ...
- C#对泛型List<T>系列化与反系列化
练习一个小例子,在C#中,怎样对泛型List<T>数据集进行系列化与反系列化.我们先了解msdn提供的JavaScriptSerializer类: JavaScriptSerializer ...
- Cocoapods配置
这真是蛋疼的东西,配置了几次,每次都不同,每次都折腾半天.这一段时间应该不会变了,记录下来. 一 换源 看了教程都说官方源https://rubygems.org/不能访问,我特意点了一下,发现能访问 ...
- Nodejs开发(1.Sublime Text 3配置)
本例使用Sublime Text 3开发 原因: 1. 有开发提示: 2. 非常easy的调试运行: 下载Sublime Text 3,官网地址:http://www.sublimetext.com/ ...
- wordpress搬家到本地URL修改问题
把原来服务器上面的WordPress的数据库和目录文件全部备份下来,在本地用xampp搭了一个服务器,然后将数据库和目录文件全部导入,更改conf文件中的数据库账号密码.没想到本地网站的所有CSS样式 ...
- Maven-004-使用 Nexus 搭建 maven 私服
从去年至今,自己一直在学习自动化测试工具,想利用自动化工具尽可能的将重复的.关键的.耗时耗力的工作实现自动化,减轻日常测试工作,提升测试效率.在学习的过程中,将 maven 作为了项目开发管理工具,进 ...
- freemarker学习
链接: http://swiftlet.net/archives/category/freemarker
- CentOS6.5安装配置SVN
安装SVN软件包[root@localhost ~]# yum install subversion#确认是否已安装svn模块[root@localhost ~]# cd /etc/httpd/mod ...
- ubuntu /etc/network/interfaces 中配置虚拟链路
ubuntu /etc/network/interfaces 中配置虚拟链路 平常做一些关于网络的测试时,像一些需要在二层上运行的功能,一个网卡不足够的情况下,可使用 ip link 工具加一些虚拟的 ...