HDU 4283 (第k个出场 区间DP)
http://blog.csdn.net/acm_cxlove/article/details/7964594
http://www.tuicool.com/articles/jyaQ7n
http://blog.csdn.net/woshi250hua/article/details/7973824
记忆化搜索(15MS):
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <cctype>
#include <vector>
#include <iterator>
#include <set>
#include <map>
#include <sstream>
using namespace std; #define mem(a,b) memset(a,b,sizeof(a))
#define pf printf
#define sf scanf
#define spf sprintf
#define pb push_back
#define debug printf("!\n")
#define INF 10000
#define MAX(a,b) a>b?a:b
#define blank pf("\n")
#define LL long long
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define pqueue priority_queue const int MAXN = + ; int n,m; int dp[][];
int a[],sum[]; int solve(int i,int j)
{
int& ans = dp[i][j];
if(ans!=-) return ans;
if(i>=j) return ;
ans = <<;
for(int k = ;k<=j-i+;k++)
{
ans = min(ans,solve(i+,i+k-)+solve(i+k,j) + (k-)*a[i] + (sum[j]-sum[i+k-])*k);
}
return ans;
} int main()
{
int i,j;
int t;
cin>>t;
while(t--)
{
cin>>n;
sum[]=;
for(i=;i<=n;i++)
{
sf("%d",&a[i]);
sum[i]=sum[i-]+a[i];
}
mem(dp,-);
pf("%d\n",solve(,n));
}
return ;
}
递推:
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <cctype>
#include <vector>
#include <iterator>
#include <set>
#include <map>
#include <sstream>
using namespace std; #define mem(a,b) memset(a,b,sizeof(a))
#define pf printf
#define sf scanf
#define spf sprintf
#define pb push_back
#define debug printf("!\n")
#define INF 10000
#define MAX(a,b) a>b?a:b
#define blank pf("\n")
#define LL long long
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define pqueue priority_queue const int MAXN = + ; int n,m; int dp[][];
int a[],sum[]; int main()
{
int i,j;
int t;
cin>>t;
while(t--)
{
cin>>n;
sum[]=;
for(i=;i<=n;i++)
{
sf("%d",&a[i]);
sum[i]=sum[i-]+a[i];
}
mem(dp,);
for(int l = ;l<=n;l++)
{
for(i=;i<=n-l+;i++)
{
j = i+l-;
dp[i][j] = <<;
for(int k = ;k<=l;k++)
{
dp[i][j] = min(dp[i][j],dp[i+][i+k-] + dp[i+k][j] + (k-)*a[i] + (sum[j]-sum[i+k-])*k);
}
}
}
pf("%d\n",dp[][n]); }
return ;
}
HDU 4283 (第k个出场 区间DP)的更多相关文章
- HDU 4283 You Are the One ——区间dp
参考了许多大佬 尤其是https://blog.csdn.net/woshi250hua/article/details/7973824这一篇 ,最后我再加一点我的见解. 大意是 给定一个序列,序列 ...
- hdu 4283 You Are the One 区间dp
You Are the One Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 4283"You Are the One"(区间DP)
传送门 https://www.cnblogs.com/violet-acmer/p/9852294.html 题意: 有n个屌丝排成一排,每个屌丝都有一个不开心值a[ i ]( i=1,2,3,.. ...
- 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 5900 QSC and Master (区间DP)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5900 题意:给出序列$A_{i}.key$和$A_{i}.value$,若当前相邻的两个数$A_{ ...
- HDU 5115 (杀狼,区间DP)
题意:你是一个战士现在面对,一群狼,每只狼都有一定的主动攻击力和附带攻击力.你杀死一只狼.你会受到这只狼的(主动攻击力+旁边两只狼的附带攻击力)这么多伤害~现在问你如何选择杀狼的顺序使的杀完所有狼时, ...
- hdu 2476 (string painter) ( 字符串刷子 区间DP)
String painter Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 4632 子字符串统计的区间dp
题意:查找这样的子回文字符串(未必连续,但是有从左向右的顺序)个数. 简单的区间dp,哎,以为很神奇的东西,其实也是dp,只是参数改为区间,没做过此类型的题,想不到用dp,以后就 知道了,若已经知道[ ...
- HDU 2517 / POJ 1191 棋盘分割 区间DP / 记忆化搜索
题目链接: 黑书 P116 HDU 2157 棋盘分割 POJ 1191 棋盘分割 分析: 枚举所有可能的切割方法. 但如果用递归的方法要加上记忆搜索, 不能会超时... 代码: #include& ...
随机推荐
- php面试题汇集2
1.实现中文字符串截取无乱码方法 开启mbstring扩展,然后自定义函数: <?php header('content-Type:text/html:charset=utf-8'); func ...
- [译文]casperjs使用说明-使用命令行
使用命令行 Casperjs使用内置的phantomjs命令行解析器,在cli模块里,它传递参数位置的命名选项 但是不要担心不能熟练操控CLI模块的API,一个casper实例已经包含了cli属性,允 ...
- h5 fieldset
http://www.w3school.com.cn/tiy/t.asp?f=html_fieldset 这个标签可以让border里面写入文字
- ES6 (一)变量声明方法 & 解构赋值
就是最新的JavaScript 原来的是var,要求不严格,不能限制修改,函数级 es6要求严格 1.防止重复声明 let 变量=var const 常量 2.控制修改 const常量不能修 ...
- 前端之JS的线程(最易懂)
1. 前言 很多文章在介绍线程以及线程之间的关系,都存在着脱节的现象.还有的文章过于广大,涉及到了内核,本文希望以通俗易懂的话去描述晦涩的词语,可能会和实际有一丢丢的出入,但是更易理解. 我们都知道J ...
- TP5.0学习历程(1)
验证码的使用 控制器代码如下: $captcha = new \think\captcha\Captcha(); if (!$captcha->check($data['code ...
- Linux Python import jenkins 报错 oserror: /usr/lib/python2.7/site-packages/lookup3.so
安装了jenkins和Python-jenkins后,在脚本中import jenkins会报错:oserror: /usr/lib/python2.7/site-packages/lookup3.s ...
- wordcloud词云--可视化
import jieba import wordcloud f = open("新时代中国特色社会主义.txt", "r", encoding="gb ...
- Hive优化-大表join大表优化
Hive优化-大表join大表优化 5.大表join大表优化 如果Hive优化实战2中mapjoin中小表dim_seller很大呢?比如超过了1GB大小?这种就是大表join大表的问题.首先引入一个 ...
- MVC 和 MVR 的区别分析
MVC模式中,可以将路由绑定到控制器上.MVR是一对一的.路由和控制器是一个东西. 优点是需要被迫处理路由.缺点是不能在控制器被绑定到路由之前复用控制器. [1] node.js - Differen ...