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)的更多相关文章

  1. HDU 4283 You Are the One ——区间dp

    参考了许多大佬  尤其是https://blog.csdn.net/woshi250hua/article/details/7973824这一篇 ,最后我再加一点我的见解. 大意是 给定一个序列,序列 ...

  2. 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) ...

  3. hdu 4283"You Are the One"(区间DP)

    传送门 https://www.cnblogs.com/violet-acmer/p/9852294.html 题意: 有n个屌丝排成一排,每个屌丝都有一个不开心值a[ i ]( i=1,2,3,.. ...

  4. 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 ...

  5. HDU 5900 QSC and Master (区间DP)

    题目链接   http://acm.hdu.edu.cn/showproblem.php?pid=5900 题意:给出序列$A_{i}.key$和$A_{i}.value$,若当前相邻的两个数$A_{ ...

  6. HDU 5115 (杀狼,区间DP)

    题意:你是一个战士现在面对,一群狼,每只狼都有一定的主动攻击力和附带攻击力.你杀死一只狼.你会受到这只狼的(主动攻击力+旁边两只狼的附带攻击力)这么多伤害~现在问你如何选择杀狼的顺序使的杀完所有狼时, ...

  7. hdu 2476 (string painter) ( 字符串刷子 区间DP)

    String painter Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  8. hdu 4632 子字符串统计的区间dp

    题意:查找这样的子回文字符串(未必连续,但是有从左向右的顺序)个数. 简单的区间dp,哎,以为很神奇的东西,其实也是dp,只是参数改为区间,没做过此类型的题,想不到用dp,以后就 知道了,若已经知道[ ...

  9. HDU 2517 / POJ 1191 棋盘分割 区间DP / 记忆化搜索

    题目链接: 黑书 P116 HDU 2157 棋盘分割 POJ 1191 棋盘分割 分析:  枚举所有可能的切割方法. 但如果用递归的方法要加上记忆搜索, 不能会超时... 代码: #include& ...

随机推荐

  1. js中的valueOf与toString

    所有对象继承了两个转换方法: 第一个是toString(),它的作用是返回一个反映这个对象的字符串 第二个是valueOf(),它的作用是返回它相应的原始值 一般来说,对象到字符串的转换经过了如下步骤 ...

  2. Python3之文本操作

    文件操作示例分析: 文件操作一般要经历三个步骤: 打开文件 操作文件 关闭文件 读取操作示例: >>>f = open('test.txt', 'r') # 打开文件test.txt ...

  3. pip安装本地文件

    I do a lot of development without an internet connection1, so being able to install packages into a ...

  4. .net core webapi发布

    地址:https://www.cnblogs.com/laozhang-is-phi/p/9565227.html#autoid-5-1-0 地址2:https://www.cnblogs.com/f ...

  5. 接口自动化 之 unittest+ddt+openpyxl 综合

    前面写过python 之 unittest初探 和 python 之 unittest+ddt 两篇文章.在之前的文章中,写过可以再次优化.今天写第三篇的目的,就是在原有基础上,基于 openpyxl ...

  6. vscode安装golang插件失败问题

    vscode安装golang插件失败问题 dlv go-outline go-symbols gocode-gomod gocode 代码补全 godef 代码跳转 golint gopkgs gor ...

  7. python设计模式--读书笔记

    GoF在其设计模式一书中提出了23种设计模式,并将其分为三类: 创建型模式 将对象创建的细节隔离开来,代码与所创建的对象的类型无关. 结构型模式 简化结构,识别类与对象间的关系,重点关注类的继承和组合 ...

  8. Java - 二分法查找(尚学堂第七章数组)

    import java.util.Arrays; public class TestBinarySearch { public static void main(String[] args) { in ...

  9. Unix_JDK安装及配置

    CentOS 下过程 JDK 在 CentOS 和 Ubuntu 下安装过程是一样的,所以这里不再讲 Ubuntu 系统下的安装 JDK 1.8 下载 此时(20170906)最新版本:jdk-8u1 ...

  10. QQ游戏--捕鱼假日竞技港对抗岛自动刷贝壳辅助使用教程和下载地址

    首先解压缩到D盘根目录 再进入buyujiari文件夹双击 然后打开QQ游戏,进入竞技港-->对抗岛,到达开始准备的界面 再打开  辅助.exe 360对按键精灵的一个文件会提示病毒,可不用理会 ...