J. Pangu and Stones

大意: 给定$n$堆石子, $(n\le 100)$, 每次操作任选连续的至少$L$堆至多$R$堆合并, 代价为合并石子的总数, 求合并为$1$堆的最少花费.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr ({printf("dp[%d][%d][%d]=%d\n",l,r,k,dp[l][r][k]),puts("");})
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, P2 = 998244353, INF = 5e8;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head const int N = 110;
int n,L,R,a[N];
int dp[N][N][N]; int main() {
while (~scanf("%d%d%d", &n, &L, &R)) {
REP(i,1,n) scanf("%d",a+i),a[i]+=a[i-1];
REP(d,1,n) REP(k,1,n) {
for(int l=1,r=l+d-1;r<=n;++l,++r) {
int &ans = dp[l][r][k]=INF;
if (k==1) {
if (l==r) ans=0;
else if (r-l+1<L) ;
else if (r-l+1<=R) ans=a[r]-a[l-1];
else {
REP(i,L,R) REP(j,l,r-1) {
ans = min(ans,dp[l][j][1]+dp[j+1][r][i-1]);
}
ans += a[r]-a[l-1];
}
}
else {
REP(i,l,r-1) ans = min(ans, dp[l][i][1]+dp[i+1][r][k-1]);
}
}
}
printf("%d\n",dp[1][n][1]>=INF?0:dp[1][n][1]);
}
}

ACM-ICPC 2017北京的更多相关文章

  1. HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)

    HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: ...

  2. ACM ICPC 2017 Warmup Contest 9 I

    I. Older Brother Your older brother is an amateur mathematician with lots of experience. However, hi ...

  3. ACM ICPC 2017 Warmup Contest 9 L

    L. Sticky Situation While on summer camp, you are playing a game of hide-and-seek in the forest. You ...

  4. [刷题]ACM/ICPC 2016北京赛站网络赛 第1题 第3题

    第一次玩ACM...有点小紧张小兴奋.这题目好难啊,只是网赛就这么难...只把最简单的两题做出来了. 题目1: 代码: //#define _ACM_ #include<iostream> ...

  5. 2016年11月ACM/ICPC亚洲区北京赛赛后总结

    2016年11月12到11月13为期两天的比赛,这是我们这个对第一次去打亚洲区域赛,经过这次比赛,我认识到了自己与别人的差距,也许我们与别人的起点不同,但这不是理由. 这次的比赛12号的热身赛两点开始 ...

  6. icpc 2017北京 J题 Pangu and Stones 区间DP

    #1636 : Pangu and Stones 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In Chinese mythology, Pangu is the fi ...

  7. [刷题]ACM ICPC 2016北京赛站网络赛 D - Pick Your Players

    Description You are the manager of a small soccer team. After seeing the shameless behavior of your ...

  8. ACM ICPC 2017 Warmup Contest 1 D

    Daydreaming Stockbroker Gina Reed, the famous stockbroker, is having a slow day at work, and between ...

  9. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  10. 2017 ACM/ICPC Asia Regional Shenyang Online spfa+最长路

    transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/1 ...

随机推荐

  1. 动态拼接tr,th

    var dltable=''; // <c:forEach items="data" var="data" ></c:forEach> ...

  2. 基于OVS命令的VLAN实现

    利用mininet创建如下拓扑,要求支持OpenFlow 1.3协议,主机名.交换机名以及端口对应正确 直接在Open vSwitch下发流表,实现如下连通性要求 h1 -- h4互通 h2 -- h ...

  3. Matlab下imwrite,Uint16的深度图像

    Matlab下imwrite,Uint16的深度图像 1. 在Matlab命令窗口输入命令: help imwrite 会有如下解释: If the input array is of class u ...

  4. 算法-java实现

    1. 质因数分解 public static List<Integer> factorize(int n){ List<Integer> factors = new Array ...

  5. 字符串匹配 - hash

    之前有写过一篇hash表,不过那是非常久远的时候了,应该是大一刚学一个学期的时候的成果,后来也就不那样写了,后来从xiaoxin那里学习了hash的写法,比较容易用也比较方便多hash,就这样. 分别 ...

  6. hashMap 底层原理+LinkedHashMap 底层原理+常见面试题

    1.源码 java1.7    hashMap 底层实现是数组+链表 java1.8 对上面进行优化  数组+链表+红黑树 2.hashmap  是怎么保存数据的. 在hashmap 中有这样一个结构 ...

  7. MongoDB安装成windows 服务

    观看本文之间,请先移步至下面纠正部分 之前按照MongoDB官网提供的安装方法一直出错 http://cn.docs.mongodb.org/master/tutorial/install-mongo ...

  8. <iframe>和<frame>标签属性详解

    iframe>元素会创建包含另外一个文档的内联框架(即行内框架): 一.align 属性(不赞成) align属性规定iframe相对于周围元素的水平和垂直对齐方式,因为iframe元素是行内元 ...

  9. qt ui

    /******************************************************************************** ** Form generated ...

  10. JavaScript 异步和单线程

    JavaScript语言本身是单线程的,所以它自身不可能是异步.所谓单线程,就必然意味着:所有任务需要排队,前一个任务结束,才会执行后一个任务. 但js的宿主环境(比如浏览器,Node)是多线程的.宿 ...