hdu 4283 区间dp
You Are the One
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3348 Accepted Submission(s): 1524
The next n line are n integer D1-Dn means the value of diaosi of boys (0 <= Di <= 100)
2
3
4
5
4
3
2
2
/*
hdu 4283 区间dp problem:
给定一个序列,序列内的人有值Di,然后将这个序列的人进栈,第i个人如果是第k个出栈,那么最后的总值增加
Di*(k-1), 求一个出栈序列使得总值最小。 solve:
对于[1,n]而言,如果1是第k个出栈,那么[2,k]肯定比1先出栈,[k+1,n]肯定比1后出栈.于是求能划分出子区间
所以可以用区间DP解决,只是在合并的时候需要处理 study:http://blog.csdn.net/woshi250hua/article/details/7969225
2016-08-17 16:57:17
*/
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#define lson i<<1
#define rson i<<1|1
#define ll long long
#define key_val ch[ch[root][1]][0]
using namespace std;
const int maxn = 1010;
const int inf = 0x3f3f3f3f;
int dp[105][105];
int a[maxn];
int sum[maxn]; int main()
{
// freopen("in.txt","r",stdin);
int T,cas = 1;
scanf("%d",&T);
while(T--)
{
int n;
sum[0] = 0;
printf("Case #%d: ",cas++);
scanf("%d",&n);
for(int i = 1;i <= n;i++)
{
for(int j = i + 1;j <= n;j++)
dp[i][j] = inf;
}
for(int i = 1; i <= n; i++)
{
scanf("%d",&a[i]);
sum[i] = sum[i-1] + a[i];
// cout << a[i] << endl;
} for(int lgd = 1; lgd < n; lgd++)
{
for(int i = 1; i + lgd <= n; i++)
{
int j = i + lgd;
for(int k = i; k <= j; k++)
{
int tp = (k-i)*a[i];
tp += dp[i+1][k] + dp[k+1][j];
tp += (k-i+1)*(sum[j] - sum[k]);
dp[i][j] = min(dp[i][j],tp);
}
}
}
printf("%d\n",dp[1][n]);
}
return 0;
}
hdu 4283 区间dp的更多相关文章
- HDU 4283 区间DP You Are the One
题解 我使用记忆化搜索写的.
- HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化
HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化 n个节点n-1条线性边,炸掉M条边也就是分为m+1个区间 问你各个区间的总策略值最少的炸法 就题目本身而言,中规中矩的 ...
- HDU 4293---Groups(区间DP)
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=4293 Problem Description After the regional con ...
- String painter HDU - 2476 -区间DP
HDU - 2476 思路:分解问题,先考虑从一个空串染色成 B串的最小花费 ,区间DP可以解决这个问题 具体的就是,当 str [ l ] = = str [ r ]时 dp [ L ] [ R ] ...
- HDU 4632 区间DP 取模
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4632 注意到任意一个回文子序列收尾两个字符一定是相同的,于是可以区间dp,用dp[i][j]表示原字 ...
- 2016 ACM/ICPC Asia Regional Shenyang Online 1009/HDU 5900 区间dp
QSC and Master Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- HDU 4570(区间dp)
E - Multi-bit Trie Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- hdu 2476 区间dp
题意: 给出两个串s1和s2,一次只能将一个区间刷一次,问最少几次能让s1=s2 例如zzzzzfzzzzz,长度为11,我们就将下标看做0~10 先将0~10刷一次,变成aaaaaaaaaaa 1~ ...
- hdu 4632(区间dp)
Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65535 K (Java/ ...
随机推荐
- Beta冲刺NO.1
Beta冲刺 第一天 1. 昨天的困难 由于今天还是第一天,所以暂时没有昨天的困难. 2. 今天解决的进度 潘伟靖: 对代码进行了review 1.将某些硬编码改为软编码 2.合并了一些方法,简化代码 ...
- cpp常用函数总结
//sprintf sprintf(temp_str_result, "%lf", temp_double); result = temp_str_result; (*begin) ...
- 【技巧】Java工程中的Debug信息分级输出接口及部署模式
也许本文的标题你们没咋看懂.但是,本文将带大家领略输出调试的威力. 灵感来源 说到灵感,其实是源于笔者在修复服务器的ssh故障时的一个发现. 这个学期初,同袍(容我来一波广告产品页面,同袍官网)原服务 ...
- JAVA_SE基础——35.static修饰成员函数
在Java中适用static关键字修饰的方法称为静态方法. 声明静态方法的语法格式如下: 权限修饰符 static 数据类型 方法名(){ 方法体 } 静态方法 可以使用类名直接调用 类名.方 ...
- python 学习笔记
1. 关于两者详细解释,参考链接:www.crifan.com/python_re_search_vs_re_findall/ 代码图
- 验证码进阶(TensorFlow--基于卷积神经网络的验证码识别)
本人的第一个深度学习实战项目,参考了网络上诸多牛人的代码,在此谢过,因时间久已,不记出处,就不一一列出,罪过罪过. 我的数据集是我用脚本在网页上扒的,标签是用之前写的验证码识别方法打的.大概用了400 ...
- Django REST framework+Vue 打造生鲜超市(二)
三.Models设计 3.1.项目初始化 (1)进虚拟环境下安装 django2.0.2 djangorestframework和相关依赖mark,filter pillow 图片处理 pip in ...
- C#配置文件config的使用
做程序的时候总会有一些参数,可能会调整,这时候一般情况下我都会写在配置文件里,这样方便一点. 配置文件的读取 <?xml version="1.0" encoding=&qu ...
- 安装shellinabox-master
安装shellinabox-master 1 插件介绍:通过web页面管理linux主机(电脑版) a. 安装 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...
- H5 input输入限制最大位数,和调用小键盘需求发生冲突的解决办法
首先,限制输入最大位数时,input有自带的属性maxlength. <input type="text" name="email" maxlength= ...