题意:每个人有一个DI值,现在有一个小黑屋,这些人的顺序可以利用这个小黑屋调整,调整方式是入栈出栈方式,也就是说,这里的方案是有卡特兰数个方式。

调整后使得 d1*0 + d2*1 + d3*2 + d4*3 ...... 最小。

分析:这个题目竟然会是区间DP。

考虑区间 [ L, R ] ,那么L,可以从任意位置出栈,枚举出栈位置,可以划分为两个部分,也就是说两个子问题,但是如何利用这两个子问题得到 d[L,R],

d[L,R] = 前一部分 + D[L]*(i-L) + 后一部分 + 后一部分进位。

其中,后一部分的进位是一个前缀和*进多少位。

#include <bits/stdc++.h>

using namespace std;

const int maxn = ;
const int inf = 0x3f3f3f3f; int a[maxn];
int d[maxn][maxn];
int su[maxn]; int dp(int L,int R) {
if(L>=R) return ;
if(d[L][R]!=-) return d[L][R];
d[L][R] = inf;
for(int i=L;i<=R;i++) {
d[L][R] = min(d[L][R], dp(L+, i)+(i-L)*a[L]+dp(i+, R)+(su[R]-su[i])*(i+-L));
}
return d[L][R];
} int main()
{
//freopen("in.txt","r",stdin);
int t;
scanf("%d",&t);
int kase = ;
while(t--) {
int n;
scanf("%d",&n); memset(d,-,sizeof(d));
memset(su,,sizeof(su)); for(int i=;i<=n;i++) {
scanf("%d",&a[i]);
su[i] = su[i-] + a[i]; //前缀和
} printf("Case #%d: %d\n",kase++,dp(,n)); }
return ;
}

HDU 4278 卡特兰,区间DP的更多相关文章

  1. hdu 5396 Expression(区间dp)

    Problem Description Teacher Mai has n numbers a1,a2,⋯,anand n−1 operators("+", "-&quo ...

  2. You Are the One HDU - 4283 (区间DP)

    Problem Description The TV shows such as You Are the One has been very popular. In order to meet the ...

  3. Dire Wolf HDU - 5115(区间dp)

    Dire Wolf Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)Total ...

  4. HDU 5568 sequence2 区间dp+大数

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5568 题意: 求所有长度为k的严格升序子序列的个数. 题解: 令dp[i][k]表示以i结尾的长度为 ...

  5. hdu 4579 博弈+区间dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4597 #include <cstdio> #include <cstring> ...

  6. Hdu 2513 区间DP

    Cake slicing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  7. hdu 5181 numbers——思路+区间DP

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5181 题解:https://www.cnblogs.com/Miracevin/p/10960717.ht ...

  8. HDU 4283---You Are the One(区间DP)

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=4283 Problem Description The TV shows such as Y ...

  9. HDU 4293---Groups(区间DP)

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=4293 Problem Description After the regional con ...

随机推荐

  1. pinyin4j的基本使用

    PinYin4jUtils工具类代码:http://www.cnblogs.com/jepson6669/p/8856082.html maven中引入依赖 <!-- 引入pinyin4J的依赖 ...

  2. k8s单节点集群部署应用

    之所以用k8s来部署应用,就是因为k8s可以灵活的控制集群规模,进行扩充或者收缩.生产上我们要配置的参数较多,命令行的方式显然不能满足需求,我们应该使用基于配置文件的方式.接下来做一个部署的demo: ...

  3. 1.2 js基础

    1.onchange    99%用到select上边. 2.js是干什么的,修改css样式和属性   3.选项卡步骤   1.获取元素 2.循环给按钮加自定义属性 3.循环给按钮加事件   4.封装 ...

  4. jqgrid 增删改页面快速构建

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="InvitationRout ...

  5. maven 基本配置

    <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave ...

  6. SpringMVC框架下实现分页功能

    1.创建实体类Page.java @Entity public class Page { private int totalRecord;// 表示查询后一共得到多少条结果记录 private int ...

  7. Hashtable(哈希表)

    简体字繁体字转化: class Program { static void Main(string[] args) { Hashtable ht = new Hashtable(); ; i < ...

  8. 1.浅析Hadoop之HDFS

    HDFS ,Hadoop Distribute File System,hadoop分布式文件系统. 主从架构,分主节点NameNode,从节点DataNode.当然还有个SecondaryName, ...

  9. spring boot 2.0.0 + mybatis 报:Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

    spring boot 2.0.0 + mybatis 报:Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required 无法启动 ...

  10. Cocos2d-js 开发记录:图片数据资源等的异步加载

    这里说的是在需要的使用加载图片,比如游戏中的某个关卡的图片,不用在游戏一开始就加载(万一用户玩不到那关,岂不是很冤,流量费了那么多),否则载入速度也慢.这种方式加载资源要用到cc.loader官方文档 ...