HDU 4278 卡特兰,区间DP
题意:每个人有一个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的更多相关文章
- hdu 5396 Expression(区间dp)
Problem Description Teacher Mai has n numbers a1,a2,⋯,anand n−1 operators("+", "-&quo ...
- 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 ...
- Dire Wolf HDU - 5115(区间dp)
Dire Wolf Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)Total ...
- HDU 5568 sequence2 区间dp+大数
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5568 题意: 求所有长度为k的严格升序子序列的个数. 题解: 令dp[i][k]表示以i结尾的长度为 ...
- hdu 4579 博弈+区间dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4597 #include <cstdio> #include <cstring> ...
- Hdu 2513 区间DP
Cake slicing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- hdu 5181 numbers——思路+区间DP
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5181 题解:https://www.cnblogs.com/Miracevin/p/10960717.ht ...
- 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 ...
- HDU 4293---Groups(区间DP)
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=4293 Problem Description After the regional con ...
随机推荐
- Permanent data region free space insufficient to allocate 64792 bytes of memory
TT0802: Database permanent space exhaustedTT6220: Permanent data region free space insufficient to a ...
- matlab中如何根据t检验参数查找t检验值
这个问题花了一些时间.先看图 这个是t检验里面的公式,但是如何在matlab中找到该式子对应的值,我现在才知道. 就是这样:x=tinv(1-α/2,n-1)----t(n)分布的上侧α分位数 ...
- js event鼠标事件
1,鼠标焦点事件 <!DOCTYPE html><html lang="en"><head> <meta charset="UT ...
- mysql 查两个表相同的值
比如一个数据库 表A和表B 都有一个username字段, 现查出与表A中username值相同的表B的username和password数据 select B.username,B.password ...
- Git代码merge
Git代码合并遇到如下问题: <<<<<<< HEAD client.post(url, secretKey, function (data, res ...
- 如何用 windows+github搭建一个优美的hexo博客
1.Hexo简单介绍 Hexo 是一个快速.简洁且高效的博客框架.Hexo 使用 Markdown(或其他渲染引擎)解析文章,在几秒内,即可利用靓丽的主题生成静态网页. 风一般的速度Hexo基于Nod ...
- 通过学生-课程关系表,熟悉hive语句
通过学生-课程关系表,熟悉hive语句 1.在hive中创建以下三个表. create table student(Sno int,Sname string,Sex string,Sage int, ...
- 五校联考模拟赛Day2T2矩阵(容斥原理)
题意 $n * m$的网格,对其进行黑白染色,问每一行每一列至少有一个黑格子的方案数. Sol 考场上只会$n^3$的dp,还和指数级枚举一个分qwq 设$f[i][j]$表示到了第$i$行,已经有$ ...
- 封装微信jssdk自定义分享代码
var protocol = window.location.protocol; //获取协议 var host = window.location.host; //获取域名 var posuDoma ...
- JavaScript中8个容易犯的错误
这里dbestech针对JavaScript初学者给出一些技巧和列出一些陷阱. 1. 你是否尝试过对数组元素进行排序? JavaScript默认使用字典序(alphanumeric)来排序.因此,[1 ...