HDU 4283 You Are the One
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const LL INF = 0xfffffff;
const LL maxn = ;
int dp[maxn][maxn], a[maxn], sum[maxn]; int DFS(int L,int R)
{
if(dp[L][R])
return dp[L][R];
if(L > R)
return ; dp[L][R] = INF;
for(int k=; k<=R-L; k++)///在区间【L,R】内,这个数该如何去选择
{///假设第L个数字,要在第K次选择
dp[L][R] = min(dp[L][R], DFS(L+, L+k) + a[L]*k + DFS(L+k+,R) + (sum[R]-sum[L+k])*(k+) );
}
// printf("dp[%d][%d]:%d\n",L, R, dp[L][R]);
return dp[L][R];
}
/*
第L个元素第k个出场拍,
*/
int main()
{
int T, n, cas = ;
scanf("%d", &T);
while(T--)
{
scanf("%d", &n);
memset(dp, , sizeof(dp));
for(int i=; i<n; i++)
scanf("%d", &a[i]);
sum[] = a[]; for(int i=; i<n; i++)
sum[i] = sum[i-] + a[i]; printf("Case #%d: %d\n",cas ++, DFS(, n-));
}
return ;
} /*
2
2
4 5 2
5
1 2 3 4 5 5
5 4 3 2 2
*/
HDU 4283 You Are the One的更多相关文章
- hdu 4283 区间dp
You Are the One Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU 4283 You Are the One(区间DP(最优出栈顺序))
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4283 题目大意:有一群屌丝,每个屌丝有个屌丝值,如果他第K个上场,屌丝值就为a[i]*(k-1),通过 ...
- HDU 4283:You Are the One(区间DP)
http://acm.hdu.edu.cn/showproblem.php?pid=4283 题意:有n个数字,不操作的情况下从左到右按顺序输出,但是可以先让前面的数字进栈,让后面的数字输出,然后栈里 ...
- HDU 4283 You Are the One (12年天津 区间DP)
题意:有一个队列,每个人有一个愤怒值a[i],如果他是第k个上场,不开心指数就为(k-1)*a[i].但是边上有一个小黑屋(其实就是个堆栈),可以一定程度上调整上场程序 思路:枚举区间和每个人第几个上 ...
- 区间DP HDU 4283
t个数据 n个权值 1->n 可以入栈调整顺序 花费 第k个出来 w[i]*(k-1); 求花费最少 #include<stdio.h> #include<string.h&g ...
- 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) ...
- HDU 4283 You are the one(间隔DP)
标题效果: The TV shows such as You Are the One has been very popular. In order to meet the need of boys ...
- You Are the One HDU - 4283 (区间DP)
Problem Description The TV shows such as You Are the One has been very popular. In order to meet the ...
- HDU 4283 You Are the One 【区间DP】
<题目链接> 题目大意: 有$n$个人排成一排要上台表演,每个人有一个屌丝值$pi$.第i个上台表演的人,他的不满意度为$(i-1)*p_i$.现在有一个类似于栈的黑屋子,你可以让某些人进 ...
随机推荐
- Stream流的读取使用
这个是在现在的项目里,用到的知识点,一般用不到这些..所以想着还是记下来以后用. 针对文本流 //StreamReader sr = new StreamReader(mystream,Encodin ...
- EMA计算的C#实现(c# Exponential Moving Average (EMA) indicator )
原来国外有个源码(TechnicalAnalysisEngine src 1.25)内部对EMA的计算是: var copyInputValues = input.ToList(); for (int ...
- CSS居中的方法总结
[水平居中] 行内:text-align:center; 定宽块状:1.left:0 right:0然后用margin: auto外边距填充,水平方向不会发生外边距叠加; 2.绝对定位(父元素定位不 ...
- 浅谈html5某些新元素的用途
大家都知道html是一种前端网页语言,从出现到现在已经经历了很多的版本了,但是随着html的不断发展,现在的html5已经不再是单一的前端页面语言了,html,javascript,css不再单纯的只 ...
- ejs 基本语法
1.基本语法.<% code %> 无缓冲的条件语句元素.<%= code %> 转义HTML,该code并且会打印出来.<%- code %> ...
- 115个Java面试题和答案——终极列表
from http://www.importnew.com/10980.html#collection http://www.importnew.com/11028.html 下面的章节分为上下两篇, ...
- MySQL数据库服务器 主从配置
A B 为两台 MySQL 服务器,均开启二进制日志,数据库版本 MySQL 5.5 一.服务器参数 [A 服务器 192.168.1.100] server-id = 1 binlog-do-d ...
- tab选项卡-jQuery
上次用原生的js写了个tab选项卡 这次按照一样的思路用jQuery写了一个 ,直接看代码: /*布局*/ <div id="div1"> <input cl ...
- call 方法在使用一个指定的this值和若干个指定的参数值的前提下调用某个函数或方法.
call 方法在使用一个指定的this值和若干个指定的参数值的前提下调用某个函数或方法. 注意:该函数的语法与 apply() 方法的语法几乎完全相同,唯一的区别在于,apply()方法接受的是一个参 ...
- PHP框架_ThinkPHP数据库
目录 1.ThinkPHP数据库配置 2.ThinkPHP数据库实例化模型 3.ThinkPHP数据库CURD操作 4.ThinkPHP数据库连贯操作 1.ThinkPHP数据库配置 App/Conf ...