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. (转)spring mvc forward与redirect

    forward 转发,如return "forward:/hello"; 浏览器的地址栏不会变,但是有视图返回来 redirect 重定向,如return "redire ...

  2. python 中字典的操作(增、删、改、查)

    字典是另一种可变容器模型,且可存储任意类型对象,下标从0开始,最后一个为-1. 字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分割,整个字典包括在花括号({}) ...

  3. Linux查看系统与内核信息(uname、file和lsb_release -a)

    uname 命令 uname 命令可以用来查看系统与内核的相关信息,命令格式如下: [root@localhost ~]# uname [选项] 选项: -a:查看系统所有相关信息: -r:查看内核版 ...

  4. Appium移动自动化

    一. 安装node.js 因为Appium是使用nodejs实现的,所以node是解释器,首先需要确认安装好 官网下载node.js:https://nodejs.org/en/download/ 安 ...

  5. 在python3下对数据分块(8x8大小)使用OpenCV的离散余弦变换DCT

    在MATLAB中有blkproc (blockproc)对数据处理, 在python下没找到对应的Function, 这里利用numpy 的split(hsplit和vsplit) 对数据分块处理成8 ...

  6. 【VS Error】VS2008在编译时出现:Error 15 Cannot register assembly

    现象: 在visual studio 2008在编译类库时提示如下错误: Error 15 Cannot register assembly "D:\01_Work\02_SVN\OCRpl ...

  7. debug教程

    名称 解释 格式 a (Assemble) 逐行汇编 a [address] c (Compare) 比较两内存块 c range address d (Dump) 内存16进制显示 d [addre ...

  8. 20145310《Java程序设计》第4次实验报告

    20145310<Java程序设计>第4次实验报告 实验内容 搭建Android环境 运行Android 修改代码并输出自己的学号 实验步骤 搭建Android环境 安装Android S ...

  9. 20145322何志威 《Java程序设计》课程总结

    课程总结 每周读书笔记链接汇总 •第一周读书笔记 •第二周读书笔记 •第三周读书笔记 •第四周读书笔记 •第五周读书笔记 •第六周读书笔记 •第七周读书笔记 •第八周读书笔记 •第九周读书笔记 •第十 ...

  10. HTTP-java模拟Post请求小栗子

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import ...