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]);
}
}

最新文章

  1. linux中touch命令参数修改文件的时间戳(转)
  2. Angular中的Error: [$resource:badcfg]错误如何解决之一种
  3. 节点属性(DOM对象)
  4. windows下安装python的C扩展编译环境(解决“Unable to find vcvarsall.bat”)
  5. 提交到svn服务器时,一直缓冲不,
  6. 福州大学软件工程1916|W班 第5次作业成绩排名
  7. zabbix-3.4.14源码安装
  8. Nginx 学习笔记(四)nginx-module-vts模块
  9. Java—集合框架详解
  10. Linux基础命令---iptables-save
  11. git commit -am &quot;remark&quot; 提交
  12. Linux命令(十四) 查看工作目录文件 ls
  13. JDK9-模块化系统
  14. python参数传递方式
  15. bzoj 2011
  16. python匹配两个字符串中间的字符串
  17. 设置Web AppBuilder的HTTP代理
  18. 【转】全面了解Mysql中的事务
  19. hihocoder1322 树结构判定(161周)
  20. Ubuntu 分区以及各个挂载目录的基本含义

热门文章

  1. Js中Array常用方法小结
  2. python 装饰器应用
  3. Qt内的各种路径(让人迷惑)
  4. Maven Web项目出现org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException错误
  5. 关于安卓端 点击button时出现橙色边框
  6. arcgis python pdf合并
  7. Flume-自定义 Interceptor(拦截器)
  8. wan口的ip是干什么用的
  9. 001-多线程-锁-架构【同步锁、JUC锁】
  10. 阶段5 3.微服务项目【学成在线】_day01 搭建环境 CMS服务端开发_01-项目概述-功能构架-项目背景