hdu 4283 You Are the One 区间dp

时间:2022-09-07 09:58:42

You Are the One

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Problem Description
 
 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?
 
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
 
Source
#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的更多相关文章

  1. hdu 4283&quot&semi;You Are the One&quot&semi;&lpar;区间DP&rpar;

    传送门 https://www.cnblogs.com/violet-acmer/p/9852294.html 题意: 有n个屌丝排成一排,每个屌丝都有一个不开心值a[ i ]( i=1,2,3,.. ...

  2. HDU 4283 You Are the One ——区间dp

    参考了许多大佬  尤其是https://blog.csdn.net/woshi250hua/article/details/7973824这一篇 ,最后我再加一点我的见解. 大意是 给定一个序列,序列 ...

  3. HDU 4283 &lpar;第k个出场 区间DP&rpar;

    http://blog.csdn.net/acm_cxlove/article/details/7964594 http://www.tuicool.com/articles/jyaQ7n http: ...

  4. 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 ...

  5. HDU 5900 QSC and Master (区间DP)

    题目链接   http://acm.hdu.edu.cn/showproblem.php?pid=5900 题意:给出序列$A_{i}.key$和$A_{i}.value$,若当前相邻的两个数$A_{ ...

  6. HDU 5115 (杀狼,区间DP)

    题意:你是一个战士现在面对,一群狼,每只狼都有一定的主动攻击力和附带攻击力.你杀死一只狼.你会受到这只狼的(主动攻击力+旁边两只狼的附带攻击力)这么多伤害~现在问你如何选择杀狼的顺序使的杀完所有狼时, ...

  7. hdu 4632 子字符串统计的区间dp

    题意:查找这样的子回文字符串(未必连续,但是有从左向右的顺序)个数. 简单的区间dp,哎,以为很神奇的东西,其实也是dp,只是参数改为区间,没做过此类型的题,想不到用dp,以后就 知道了,若已经知道[ ...

  8. HDU 2517 &sol; POJ 1191 棋盘分割 区间DP &sol; 记忆化搜索

    题目链接: 黑书 P116 HDU 2157 棋盘分割 POJ 1191 棋盘分割 分析:  枚举所有可能的切割方法. 但如果用递归的方法要加上记忆搜索, 不能会超时... 代码: #include& ...

  9. hdu 2476 &lpar;string painter&rpar; &lpar; 字符串刷子 区间DP&rpar;

    String painter Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

随机推荐

  1. c&num; 本周时间查询

    var now = DateTime.Now();int weeknow = Convert.ToInt32(now.DayOfWeek); //因为是以星期一为第一天,所以要判断weeknow等于0 ...

  2. jsp&colon;session对象存储数据

    public void setAttribute(String key,Object obj).session对象可以调用该方法将参数object指定的对象obj添加到session对象中,并为添加的 ...

  3. IBM即将倒闭,微软也从崩溃18个月

    IBM公司20发布2014在第三季度财报.其三阶季度净利润1800万美元,下跌99.6%. 可见IBM我已经危及. 技术专家sun收购崩溃,说明一些原因,自满技术公司可能已用完.. sun以前靠小型机 ...

  4. JVM调优总结-调优方法

    JVM调优工具 Jconsole,jProfile,VisualVM Jconsole : jdk自带,功能简单,但是可以在系统有一定负荷的情况下使用.对垃圾回收算法有很详细的跟踪 JProfiler ...

  5. Spring源码解析三:IOC容器的依赖注入

    一般情况下,依赖注入的过程是发生在用户第一次向容器索要Bean是触发的,而触发依赖注入的地方就是BeanFactory的getBean方法. 这里以DefaultListableBeanFactory ...

  6. &period;htaccess 文件来进行用户组的目录权限访问控制

    <IfModule rewrite_module>RewriteEngine onRewriteRule ^((?:bootstrap|css|img|js||MathJax|video) ...

  7. SWFUpload多文件上传使用指南

    SWFUpload是一个flash和js相结合而成的文件上传插件,其功能非常强大.以前在项目中用过几次,但它的配置参数太多了,用过后就忘记怎么用了,到以后要用时又得到官网上看它的文档,真是太烦了.所以 ...

  8. MT【171】共轭相随

    $\textbf{证明:}$对任意$a,b\in R^+$, $\dfrac{1}{\sqrt{a+2b}}+\dfrac{1}{\sqrt{a+4b}}+\dfrac{1}{\sqrt{a+6b}} ...

  9. PHP7&period;x新特性

    1.太空船操作符太空船操作符用于比较两个表达式. 当$a小于. 等于或大于$b时它分别返回-1. 0或1. // Integers echo 1 <=> 1; // 0 echo 1 &l ...

  10. &lbrack;BZOJ3000&rsqb;Big Number&lpar;斯特林公式&rpar;

    求n!在k进制下的位数,n<=1e18 斯特林公式:$n!\approx \sqrt{2\pi n}(\frac{n}{e})^n$ 在n很大的时候有较好的精度保证. $\log_{k}n!+1 ...