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 ...
随机推荐
- JAVA程序设计 实验一
北京电子科技学院(BESTI) 实 验 报 告 课程:Java程序设计 班级:1353 姓名:李海空 学号:20135329 成绩: 指导教师:娄嘉鹏 ...
- 【iCore3 双核心板_FPGA】例程九:状态机实验——状态机使用
实验指导书及代码包下载: http://pan.baidu.com/s/1o72i3mq iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...
- NGUI 之 不为人知的 NGUITools
static public float soundVolume该属性是全局音效播放音量,按照文档说是用于NGUITools.PlaySound(),那也就意味着我的游戏如果用NGUITools.Pla ...
- word-break、word-wrap和其他文字属性
word-break: break-all; 控制是否断词.(粗暴方式断词)break-all,是断开单词.在单词到边界时,下个字母自动到下一行.主要解决了长串英文的问题. word-wrap: br ...
- iOS UITableView 移除单元格选中时的高亮状态
在处理UITableView表格时,我们希望用户能够和触摸单元格式进行交互,但是希望用户在完成交互之后,这些单元格的选中状态能够消失,.Cocoa Touch 提供了两种方法来防止单元格背持久选中. ...
- VMware简介
VMware(中文名威睿”) 虚拟机软件,是全球桌面到数据中心虚拟化解决方案的领导厂商.VMware vSphere 是VMware 的一个虚拟化产品,它包括vCenter,ESX Server,ES ...
- bbs网站 models
bbs网站 models #!/usr/bin/env python #_*_coding:utf-8_*_ from django.db import models from django.cont ...
- lua OOP实现对象的链式调用
数学中的链式法则 http://sx.zxxk.com/ArticleInfo.aspx?InfoID=164649 链式微分法则:实数运算的链式法则:对数运算的链式法则:平行公理的链式法则:向量运算 ...
- [转] PHP计算两个坐标之间的距离, Calculate the Distance Between Two Points in PHP
Calculate the Distance Between Two Points in PHP There are a lot of applications where it is useful ...
- Centos 安装 MySql
下载mysql下载链接:http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.10-linux-glibc2.5-i686.tar.gz 下载后 ...