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

    1.信息增益的定义,也就是互信息 2.信息增益的推导 由公式即可得到信息增益 信息增益存在偏向于选择取值较多的特征的问题,信息增益比可以对这一问题进行修正 3.信息增益比 4.基尼指数,基尼指数越大, ...

  2. python全栈开发从入门到放弃之递归函数的调用

    1.递归效率低,需要在进入下一次递归时保留当前的状态,见51cto博客 解决方法是尾递归,即在函数的最后一步(而非最后一行)调用自动但是python又没有尾递归,且对递归层级做了限制 必须有一个明确的 ...

  3. hdu6215 Brute Force Sorting

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6215 题目: Brute Force Sorting Time Limit: 1000/100 ...

  4. “使用驱动器中J:的光盘之前需要将其格式化

    不知道神马原因致使U盘无法打开——大家千万注意:以后遇见这种情况千万别格式化(当然如果你的U盘或者硬盘里没有重要东西那就另当别论),进入“开始-cmd”,因为我的U盘在电脑上读出来是J盘,所以在cmd ...

  5. list元素排序需要满足两个条件

    关于List 说到list,我的印象就是单值集合接口,插入取出是有序的,允许重复,用他的实现类用的最频繁的就是ArrayList了.如果我现在有一个list,插入了一些值,想让里面的值按照我自定义的规 ...

  6. 20145327 实验四 Andoid开发基础

    20145327 实验四 Andoid开发基础 安装Android Studio 安装过程出现未找到SDK的错误,只需在打开界面找到右下角的设置按钮,将路径设置为如下就可以运行.(默认安装路径) 设计 ...

  7. CentOS 64位系统 yum安装32位软件包的方法

    //假如你要安装libjpeg的32位版本 1.查询具体的32位版本,然后安装 yum search libjpeg.i686 yum -y install libjpeg.i386 2.一劳永逸的方 ...

  8. MR案例:路径过滤PathFilter

    问题描述:现有一批cookie日志,按照日期进行存放,如目录 “dir/2015-08-08” 下存放2015-08-08这一天的所有cookie.而目录 “/2015-08-08/” 下又根据数据文 ...

  9. 什么是“QQ登录OAuth2.0”

    1. 什么是“QQ登录OAuth2.0 OAuth: OAuth(开放授权)是一个开放标准,允许用户授权第三方网站访问他们存储在另外的服务提供者上的信息,而不需要将用户名和密码提供给第三方网站或分享他 ...

  10. poj 2187:Beauty Contest(旋转卡壳)

    Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 32708   Accepted: 10156 Description Bes ...