题目链接:https://www.51nod.com/Challenge/ProblemSubmitDetail.html#!#judgeId=673021

代码:

参考博客:https://blog.csdn.net/qq_40772692/article/details/80183248

#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<vector>
#include<set>
#include<cstdio>
#include<string>
#include<deque>
using namespace std;
typedef long long LL;
#define eps 1e-8
#define INF 0x3f3f3f3f
#define maxn 105
/*struct point{
int u,w;
};
bool operator <(const point &s1,const point &s2)
{
if(s1.w!=s2.w)
return s1.w>s2.w;
else
return s1.u>s2.u;
}*/
int n,m,k,t;
int dp[maxn][maxn],value[maxn];
int main()
{
while(scanf("%d",&n)!=EOF){
for(int i=;i<=maxn-;i++){
for(int j=;j<=maxn-;j++){
dp[i][j]=INF;//初始化
}
}
memset(value,,sizeof(value));
for(int i=;i<=n;i++){
scanf("%d",&dp[i][i]);//这里偷懒了,用dp[i][i]这是存了一下输入的值
value[i]=value[i-]+dp[i][i];//前缀和
dp[i][i]=;//自己合并自己代价为0
}
dp[][]=;
for(int len=;len<=n;len++){//枚举长度
for(int i=;i+len-<=n;i++){//枚举起点
int ends=i+len-;//终点
for(int j=i;j<=ends;j++){//枚举切割点
dp[i][ends]=min(dp[i][ends],dp[i][j]+dp[j+][ends]+value[ends]-value[i-]);
}
}
}
printf("%d\n",dp[][n]);
}
return ;
}

区间dp 51nod1021的更多相关文章

  1. 51nod1021(区间dp)

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1021 题意:中文题诶- 思路:区间dp 我们用num[i]存 ...

  2. 区间dp(模板+例题)

    参考博文:区间dp小结(附经典例题) 首先,什么是区间dp?它是干什么的? 先在小区间进行DP得到最优解,然后再利用小区间的最优解合并求大区间的最优解 操作往往涉及到区间合并问题 以上. 模板如下: ...

  3. 【BZOJ-4380】Myjnie 区间DP

    4380: [POI2015]Myjnie Time Limit: 40 Sec  Memory Limit: 256 MBSec  Special JudgeSubmit: 162  Solved: ...

  4. 【POJ-1390】Blocks 区间DP

    Blocks Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5252   Accepted: 2165 Descriptio ...

  5. 区间DP LightOJ 1422 Halloween Costumes

    http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...

  6. BZOJ1055: [HAOI2008]玩具取名[区间DP]

    1055: [HAOI2008]玩具取名 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1588  Solved: 925[Submit][Statu ...

  7. poj2955 Brackets (区间dp)

    题目链接:http://poj.org/problem?id=2955 题意:给定字符串 求括号匹配最多时的子串长度. 区间dp,状态转移方程: dp[i][j]=max ( dp[i][j] , 2 ...

  8. HDU5900 QSC and Master(区间DP + 最小费用最大流)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5900 Description Every school has some legends, ...

  9. BZOJ 1260&UVa 4394 区间DP

    题意: 给一段字符串成段染色,问染成目标串最少次数. SOL: 区间DP... DP[i][j]表示从i染到j最小代价 转移:dp[i][j]=min(dp[i][j],dp[i+1][k]+dp[k ...

随机推荐

  1. Redis位图实现用户签到功能

    场景需求 适用场景如签到送积分.签到领取奖励等,大致需求如下: 签到1天送1积分,连续签到2天送2积分,3天送3积分,3天以上均送3积分等. 如果连续签到中断,则重置计数,每月初重置计数. 当月签到满 ...

  2. 【Source Insight 】之marco学习笔记2

    现在我们看先看一个 官方地址https://www.sourceinsight.com/download/macro-files/中的 autoexp.em Automatically expands ...

  3. react-navigation设置navigationOptions中Static中使用 this 的方法

    使用react-navigation时,单页面设置navigationOptions中,进行Static中 调用this 中的方法或值时,需要做如下操作 static navigationOption ...

  4. Duboo 与springboot整合

    https://github.com/apache/incubator-dubbo-spring-boot-project 当采用properties方式时,可以用下方的注解 1.pom <de ...

  5. golang 的 mysql 操作

    goLang的mysql操作,大致可分为三个步骤: 1.下载mysql驱动:go get github.com/go-sql-driver/mysql 2.建立连接:sql.Open("my ...

  6. Mysql 定时任务事件

    参考文献:https://blog.csdn.net/dream_ll/article/details/73499750

  7. APP-10-文字识别-票据识别

    1.Postman测试 2.参数 https://cloud.baidu.com/doc/OCR/OCR-API.html#.E9.80.9A.E7.94.A8.E7.A5.A8.E6.8D.AE.E ...

  8. APP-5-百度电子围栏

    1.代码部分 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <me ...

  9. django 认证系统--3

    WEB request中的认证 django使用sessions和middleware和reqeust对象联系在一起 它们通过给每一个reqeust请求添加一个request.user属性来代表当前用 ...

  10. IE (第二部分) 浏览器 中 关于浏览器模式和文本模式

    判断真正的 IE 版本 很多 JS 框架都通过 UA 判断 IE 的版本.对于 IE6,这种做法没问题( IE6 没有浏览器模式的概念,也没有其它 IE 可以把浏览器模式改为 IE6:IE7 虽然也没 ...