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堆石子合并成新的一堆,并将新的一堆石 ...
随机推荐
- iOS学习之HelloWorld工程
本文应读者要求,主要简介使用Xcode创建一个“HelloWorld”工程. 1.打开Xcode,点击新建工程 选择工程类型 2.填写工程信息 3.代码简介 // // main.m // hello ...
- PKU 1655 Balancing Act(树+树的重心)
#include<cstdio> #include<cstring> #include<algorithm> #define maxn 20005 using na ...
- Python+Appium API
1.contextscontexts(self): Returns the contexts within the current session. 返回当前会话中的上下文,使用后可以识别H5页面的控 ...
- js实现excel的解析
在浏览网页的时候不小心看到了这个github的资源(https://github.com/SheetJS/js-xlsx),真不错.之前在开发的时候曾遇到客户要求在前端解析excel并展示出来.这里记 ...
- laravel 环境配置
一.composer 安装 1.确定为最新版本的PHP 2.进入Composer官网下载页面,在页面最下方Manual Download区域选择需要的版本下载. 3.将下载的composer.phar ...
- 使用react常见的坑
触摸事件 React中的触摸事件仅用三种,touchstart, touchend, touchend,可是这种会有问题,有时候我需要滚动页面的时候,很容易触发某一个元素的touchend事件,为此笔 ...
- union遇上ntext数据类型
http://www.myhack58.com/Article/html/3/7/2011/31392.htm
- Python3.x:遍历select下拉框获取value值
Python3.x:遍历select下拉框获取value值 Select提供了三种选择方法: # 通过选项的顺序,第一个为 0 select_by_index(index) # 通过value属性 s ...
- 关于Log4Net的使用和配置
1. 添加log4net.dll引用 2.在添加引用的那层的 AssemblyInfo.cs 注册 : [assembly: log4net.Config.XmlConfigura ...
- 20145329吉东云 《Java程序设计》 第一周学习总结
一.JAVA平台概述 1.Java诞生于1995年5月23日,java体系架构分为JavaSE.JavaME.JavaEE三大平台,本章重点介绍了JavaSE.JavaSE分为四个主要部分:JVM.J ...