HDU 3506 (环形石子合并)区间dp+四边形优化
Monkey Party
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 1699 Accepted Submission(s): 769
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.
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.
5 2 4 7 6 1 3 9
#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+四边形优化的更多相关文章
- 洛谷P1880 石子合并(环形石子合并 区间DP)
题目描述 在一个圆形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分. 试设计出1个算法,计算出将N堆石子合并成1 ...
- P1880 [NOI1995]石子合并[区间dp+四边形不等式优化]
P1880 [NOI1995]石子合并 丢个地址就跑(关于四边形不等式复杂度是n方的证明) 嗯所以这题利用决策的单调性来减少k断点的枚举次数.具体看lyd书.这部分很生疏,但是我还是选择先不管了. # ...
- 石子合并——区间dp
石子合并(3种变形) <1> 题目: 有N堆石子排成一排(n<=100),现要将石子有次序地合并成一堆,规定每次只能选相邻的两堆合并成一堆,并将新的一堆的石子数,记为改次合并的得分, ...
- 51Nod 1022 石子归并 V2(区间DP+四边形优化)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1022 题目大意: N堆石子摆成一个环.现要将石子有次序地合并成 ...
- 洛谷 P1080 石子合并 ( 区间DP )
题意 : 在一个圆形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分.试设计出1个算法,计算出将N堆石子合并成1堆 ...
- 洛谷 P1880 [NOI1995] 石子合并(区间DP)
传送门 https://www.cnblogs.com/violet-acmer/p/9852294.html 题解: 这道题是石子合并问题稍微升级版 这道题和经典石子合并问题的不同在于,经典的石子合 ...
- 石子合并 区间dp模板
题意:中文题 Description 在操场上沿一直线排列着 n堆石子.现要将石子有次序地合并成一堆.规定每次只能选相邻的两堆石子合并成新的一堆, 并将新的一堆石子数记为该次合并的得分.允许在第一次合 ...
- HDU4632 Poj2955 括号匹配 整数划分 P1880 [NOI1995]石子合并 区间DP总结
题意:给定一个字符串 输出回文子序列的个数 一个字符也算一个回文 很明显的区间dp 就是要往区间小的压缩! #include<bits/stdc++.h> using namesp ...
- 石子合并 区间DP模板题
题目链接:https://vjudge.net/problem/51Nod-1021 题意 N堆石子摆成一条线.现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆石子合并成新的一堆,并将新的一堆石 ...
随机推荐
- libevent基础知识
在线手册 • 官方网站:http://libevent.org/ • 官方手册:http://www.wangafu.net/~nickm/libevent-book/ • 官方下载:http://s ...
- Selenium之使用PageFactory初始化pageobject
使用PageFactory初始化pageobject有什么作用呢,下面举个例子来说明 public BaiduPage baiduPage = PageFactory.initElements(dri ...
- PATH_INFO, SCRIPT_NAME, REQUEST_URI区别示例
- SQL各种连接——自连接、内连接、外连接、交叉连接的使用
首先准备了两个表 (Student 和 Course),其中 Student 表中的 C_S_Id 字段为外键列,关联的是 Course 表的 C_Id 主键列. 内连接(inner join):满足 ...
- scp无密码访问scp -i
网上搜索,可以发现大概有以下情况 1.使用expect交互 2.sshpass 但因为他们都需要安装第三方的软件,不适合我们这样的场景,我们很多时间是绝不允许安装其他软件在客户机上的. 我的场景是在本 ...
- vue2.0中配置文件路径
在build/webpack.base.conf.js中添加一些代码即可 module.exports = { resolve: { extensions: ['.js', '.vue', '.jso ...
- svn checkout 提示“由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。”解决方法
安装好之后再windows上checkout项目,一直出错:“由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败”:在尝试了很多次之后找到了最后的问题所在. 在网上找的方法试过了, ...
- MR案例:MR和Hive中使用Lzo压缩
在MapReduce中使用lzo压缩 1).首先将数据文件在本地使用lzop命令压缩.具体配置过详见配置hadoop集群的lzo压缩 //压缩lzop,解压缩lzop -d [root@ncst wo ...
- 【前端】jQuery选择器$()的实现原理
今天三七互娱技术面试的时候面试官问了我这个问题,当时一脸懵逼,于是好好总结一下. 当我们使用jquery选择器的时候,$(s).回默认去执行jquery内部封装好的一个init的构造函数每次申明一个j ...
- KVM配置及维护
kvm使用场景 1.公司测试环境/开发环境 测试开发环境可以使用配置低点的物理机就可以 2.公司生产环境 一般小公司没有私有云或容器团队,运维人员可能就1-2个,然后公司也不舍得花钱买商业化的私有云. ...