ACM-ICPC 2017北京
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北京的更多相关文章
- HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)
HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others) Memory Limit: ...
- ACM ICPC 2017 Warmup Contest 9 I
I. Older Brother Your older brother is an amateur mathematician with lots of experience. However, hi ...
- 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 ...
- [刷题]ACM/ICPC 2016北京赛站网络赛 第1题 第3题
第一次玩ACM...有点小紧张小兴奋.这题目好难啊,只是网赛就这么难...只把最简单的两题做出来了. 题目1: 代码: //#define _ACM_ #include<iostream> ...
- 2016年11月ACM/ICPC亚洲区北京赛赛后总结
2016年11月12到11月13为期两天的比赛,这是我们这个对第一次去打亚洲区域赛,经过这次比赛,我认识到了自己与别人的差距,也许我们与别人的起点不同,但这不是理由. 这次的比赛12号的热身赛两点开始 ...
- icpc 2017北京 J题 Pangu and Stones 区间DP
#1636 : Pangu and Stones 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In Chinese mythology, Pangu is the fi ...
- [刷题]ACM ICPC 2016北京赛站网络赛 D - Pick Your Players
Description You are the manager of a small soccer team. After seeing the shameless behavior of your ...
- ACM ICPC 2017 Warmup Contest 1 D
Daydreaming Stockbroker Gina Reed, the famous stockbroker, is having a slow day at work, and between ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- 2017 ACM/ICPC Asia Regional Shenyang Online spfa+最长路
transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 132768/1 ...
随机推荐
- easyUI的c if
{field:'domdistrict2',title:'区县',width:100}, {field:'option',title:'操作',width:fixWidth(0.08),align:' ...
- jinja2-模版简介
一 简介 在Flask中,调用render_template来对模版进行渲染,使用render_template,只需要导入这个API就可以,from flask import render_temp ...
- Python 类中__init__()方法中的形参与如何修改类中属性的值
一.__init__()方法 如果__init__()方法为 class Cat(): def __init__(self,num) : self.num=num Python中类的__init__( ...
- Vue —— 从环境搭建到发布
之前学习 Vue 的时候也是按着别人的文档一步步下载安装构建项目再运行,为了避免忘记步骤,所以还是记在这吧. 参考链接: https://www.zybuluo.com/xudongh/note/75 ...
- Canvas-基本用法
Canvas教程-MDN HTML 5 Canvas 参考手册 <canvas>是一个可以使用脚本(通常为JavaScript)来绘制图形的 HTML 元素.例如,它可以用于绘制图表.制作 ...
- js中string和json的相互转换
1.将string转成json var json={}; var myorderno=$("#myorderno").val(); json.myorderno=myorderno ...
- VLC播放器web插件接口(Part1)
本文转自:http://blog.csdn.net/xiaoxiaoxuewen/article/details/7698803Embed tag attributesTo embed the plu ...
- PHPCMS全局自定义函数 获取用户信息的办法
在这个文件中增加即可\phpcms\libs\functions\global.func.php /** * 获取当前登陆者的信息 * @param $f 取什么字段F就传什么值 */ functio ...
- 生产者-消费者问题与quene模块
生产者-消费者问题与quene模块 下面使用线程锁以及队列来模拟一个典型的案例:生产者-消费者模型.在这个场景下,商品或服务的生产者生产商品,然后将其放到类似队列的数据结构中,生产商品的时间是不确定的 ...
- Flutter 状态管理 flutter_Provide
项目的商品类别页面将大量的出现类和类中间的状态变化,这就需要状态管理.现在Flutter的状态管理方案很多,redux.bloc.state.Provide. Scoped Model : 最早的状态 ...