Monkey Party

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 1699    Accepted Submission(s): 769

Problem Description
Far
away from our world, there is a banana forest. And many lovely monkeys
live there. One day, SDH(Song Da Hou), who is the king of banana forest,
decides to hold a big party to celebrate Crazy Bananas Day. But the
little monkeys don't know each other, so as the king, SDH must do
something.
Now there are n monkeys sitting in a circle, and each
monkey has a making friends time. Also, each monkey has two neighbor.
SDH wants to introduce them to each other, and the rules are:
1.every time, he can only introduce one monkey and one of this monkey's neighbor.
2.if
he introduce A and B, then every monkey A already knows will know every
monkey B already knows, and the total time for this introducing is the
sum of the making friends time of all the monkeys A and B already knows;

3.each little monkey knows himself;
In order to begin the party and eat bananas as soon as possible, SDH want to know the mininal time he needs on introducing.
 
Input
There
is several test cases. In each case, the first line is n(1 ≤ n ≤ 1000),
which is the number of monkeys. The next line contains n positive
integers(less than 1000), means the making friends time(in order, the
first one and the last one are neighbors). The input is end of file.
 
Output
For each case, you should print a line giving the mininal time SDH needs on introducing.
 
Sample Input
8
5 2 4 7 6 1 3 9
 
Sample Output
105
 
Author
PerfectCai
 
Source
首先题意说的好麻烦,英语渣表示这是smg,意思就是N只猴子围成一个小圈圈大家一开始只认识自己,猴王每次只能挑出两个人介绍他们认识,花费的时间为这两个的时间总和。定义如果介绍了A和B,那么A认识的人也将认识B认识的,这所要的时间是所有的A&&B认识的人的时间和,模拟下发现这就是一个环形石子合并问题。
对于环形我们将N的环化为2*N的直线处理,最后答案就是MIN{dp[i][i+N-1]  | 1<=i<=N},N*2<=2000,传统做法会T,使用四边形优化。
对其优化内涵并不是很熟悉只知道这个定理但是看不太懂证明过程只能先记着了。
 #include<bits/stdc++.h>
using namespace std;
#define LL long long
#define MAX 2005
LL dp[MAX][MAX];
LL pre[MAX]={};
int s[MAX][MAX];
int a[MAX];
const LL inf=;
int main()
{
int N,m,i,j,k;
while(scanf("%d",&N)!=EOF){m=N*;
for(i=;i<=N;++i) scanf("%d",&a[i]),a[i+N]=a[i];
for(i=;i<=m;++i)
{
pre[i]=pre[i-]+a[i];
dp[i][i]=;
s[i][i]=i;
}
for(int len=;len<=m;++len)
{
for(i=,j=len;j<=m;i++,j++)
{dp[i][j]=inf;
for(k=s[i][j-];k<=s[i+][j];++k)
{ LL t=dp[i][k]+dp[k+][j]+pre[j]-pre[i-];
if(dp[i][j]>t){
dp[i][j]=t;
s[i][j]=k;
}
}
}
}
LL ans=inf;
for(i=;i<=N;++i)
if(ans>dp[i][i+N-]) ans=dp[i][i+N-];
printf("%lld\n",ans);
}
return ;
}
 

HDU 3506 (环形石子合并)区间dp+四边形优化的更多相关文章

  1. 洛谷P1880 石子合并(环形石子合并 区间DP)

    题目描述 在一个圆形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分. 试设计出1个算法,计算出将N堆石子合并成1 ...

  2. P1880 [NOI1995]石子合并[区间dp+四边形不等式优化]

    P1880 [NOI1995]石子合并 丢个地址就跑(关于四边形不等式复杂度是n方的证明) 嗯所以这题利用决策的单调性来减少k断点的枚举次数.具体看lyd书.这部分很生疏,但是我还是选择先不管了. # ...

  3. 石子合并——区间dp

    石子合并(3种变形) <1> 题目: 有N堆石子排成一排(n<=100),现要将石子有次序地合并成一堆,规定每次只能选相邻的两堆合并成一堆,并将新的一堆的石子数,记为改次合并的得分, ...

  4. 51Nod 1022 石子归并 V2(区间DP+四边形优化)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1022 题目大意: N堆石子摆成一个环.现要将石子有次序地合并成 ...

  5. 洛谷 P1080 石子合并 ( 区间DP )

    题意 : 在一个圆形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分.试设计出1个算法,计算出将N堆石子合并成1堆 ...

  6. 洛谷 P1880 [NOI1995] 石子合并(区间DP)

    传送门 https://www.cnblogs.com/violet-acmer/p/9852294.html 题解: 这道题是石子合并问题稍微升级版 这道题和经典石子合并问题的不同在于,经典的石子合 ...

  7. 石子合并 区间dp模板

    题意:中文题 Description 在操场上沿一直线排列着 n堆石子.现要将石子有次序地合并成一堆.规定每次只能选相邻的两堆石子合并成新的一堆, 并将新的一堆石子数记为该次合并的得分.允许在第一次合 ...

  8. HDU4632 Poj2955 括号匹配 整数划分 P1880 [NOI1995]石子合并 区间DP总结

    题意:给定一个字符串 输出回文子序列的个数    一个字符也算一个回文 很明显的区间dp  就是要往区间小的压缩! #include<bits/stdc++.h> using namesp ...

  9. 石子合并 区间DP模板题

    题目链接:https://vjudge.net/problem/51Nod-1021 题意 N堆石子摆成一条线.现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆石子合并成新的一堆,并将新的一堆石 ...

随机推荐

  1. yii2美化url

    http://blog.csdn.net/xundh/article/details/45418265

  2. python16_day24【restful、crm表构、认证】

    一.restful 1. pip install djangorestframework 2.settings.py INSTALLED_APPS = ( ... 'rest_framework', ...

  3. Django restframwork实现自定义数据格式的分页与搜索

    最近因为在做分页时遇到的问题很多,页浪费了好多时间,所以记录一下.以后如遇到可用省去不必要的麻烦 restframwork中的官方文档对分页和搜索页进行了详细的介绍,但是我公司需要的return的js ...

  4. Portal系统中当切换学生时仍旧停留在当前页面的实现方法

    一.BaseController.cs文件 1.OnActionExecuting方法,该方法可以被各子Controller重写 protected override void OnActionExe ...

  5. PHP的pm、pm.max_requests、memory_limit

    1.php-fpm.conf中的pm pm是来控制php-fpm的工作进程数到底是一次性产生固定不变(static)还是在运行过程中随着需要动态变化(dynamic).众所周知,工作 进程数与服务器性 ...

  6. java的TimeUtils或者DateUtils的编写心得

    一.几种常见的日期和时间类介绍 介绍时间工具类不可避免必须要去触碰几个常见的日期和时间类,所以就简单介绍一下. 1.jdk1.8之前的日期时间类 a.Date类 我们可以通过new的方式生成一个Dat ...

  7. Linux查找含有某字符串的文本文件

    转自:http://www.cnblogs.com/wangkongming/p/4476933.html 如果你想在当前目录下 查找"hello,world!"字符串,可以这样 ...

  8. Python 实例——进度条,文件读取

    进度条: import sys import time for i in range(50): sys.stdout.write("*") sys.stdout.flush() t ...

  9. 为什么修改Host不生效

    开发验证的好好的功能,提测后经常有测试反应功能有bug.很多原因都是测试切换host没生效造成的,为什么切换host后刷新页面了也没生效呢? 不生效原因: Keep-Alive 服务器在响应头设置了 ...

  10. Python基本数据类型之列表

    学习Python的列表类型需要了解和掌握什么是列表.列表的可变性.列表的访问.列表的增删改查等操作~ 1.了解列表 list1 = ['abc', 123, {1, 2, 3},[2,3]] Pyth ...