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$.现在有一个类似于栈的黑屋子,你可以让某些人进 ...
随机推荐
- Java基础知识强化01:short s = 1; s = s + 1;与short s = 1; s += 1;
1.short s = 1; s = s + 1;有没有问题?如果有怎么解决? short s = 1; s += 1;有没有问题?如果有怎么解决? 2.理解: short s=1; s=s+ ...
- Axiom3D学习日记 4.地形,天空,雾
首先需要引用Axiom.SceneManagers.Octree.dll. 地形: 载入地形配置,从一个文件中. scene.LoadWorldGeometry( "Terrain.xml& ...
- 表达式:使用API创建表达式树(4)DynamicExpression
DynamicExpression:表示动态操作.这个网上可见的资料少得可怜,但想到MVC和第三方的动态语言能在NET运行.好奇的倒腾了下 先声明两个类(有相同的方法和字段,但不是继承于同一接口的类) ...
- Java中char占用几个字节
在讨论这个问题之前,我们需要先区分unicode和UTF. unicode :统一的字符编号,仅仅提供字符与编号间映射.符号数量在不断增加,已超百万.详细:[https://zh.wikipedia. ...
- Java反射与代理
Java反射机制与动态代理,使得Java更加强大,Spring核心概念IoC.AOP就是通过反射机制与动态代理实现的. 1 Java反射 示例: User user = new User( ...
- javascript——归并方法
<script type="text/javascript"> //ECMAScript5 还新增了2个归并数组的方法:reduce()和reduceRight(). ...
- js数学方法应用
找出数组中最大的数 var values = [1, 2, 3, 4, 5, 6, 7, 8]; alert(Math.min.apply(Math,values))//8 这个技巧的关键是把 Mat ...
- YII 框架使用之——创建应用
linux环境为UBUNTU14.04,YII框架的版本是1.1.17 将下载的YII解压缩,压缩后会有三个文件夹,”demos,requirements,framework”,demos 当然就是演 ...
- 使用js判断一个对象是否为空 比如 obj={}
今天使用到js判断一个对象是否为空,js没有封装好的方法,这里最好的办法就是使用jquery里面的封装好的方法 $.isEmptyObject(obj)
- flask mysql
sudo apt-get install mysql-servermysql -u root -p sudo apt-get install python-mysqldb sudo apt-get i ...