hdu4570-区间dp
这道题的题意不是一般的难懂啊,各种查字典都没理解,还是没忍住去看了别人的博客,没想到题很简单,1-n内划分若干个区间,使的每个区间和最小,每个区间的区间和是:区间开头的数*2^区间长度. 区间dp
#include<cstdio>
#include<string.h>
#include<algorithm>
#define inf 0x3f3f3f3f
typedef long long LL;
const int maxn=;
using namespace std;
int t;
int n,m;
LL a[maxn+];
LL sum[maxn+];
LL dp[maxn+][maxn+];
void input(){
scanf("%d",&n);
memset(dp,-,sizeof(dp));
for(int i=;i<=n;i++){
scanf("%I64d",&a[i]);
sum[i]=sum[i-]+a[i];
}
}
LL dfs(int l,int r){
if(l>r) return ;
if(l==r) return dp[l][r]=a[l]*;
if(dp[l][r]!=-) return dp[l][r];
if(r-l+<) dp[l][r]=a[l]*<<(r-l+);
else dp[l][r]=(sum[r]-sum[l-])*;
for(int i=l;i<r;i++){
dp[l][r]=min(dp[l][r],dfs(l,i)+dfs(i+,r));
}
return dp[l][r];
}
void solve(){
input();
dfs(,n);
printf("%I64d\n",dp[][n]);
}
int main()
{
scanf("%d",&t);
while(t--){
solve();
}
return ;
}
hdu4570-区间dp的更多相关文章
- 【hdu4570】Multi-bit Trie 区间DP
标签: 区间dp hdu4570 http://acm.hdu.edu.cn/showproblem.php?pid=4570 题意:这题题意理解变态的.转自大神博客: 这题题意确实有点难懂,起码对于 ...
- HDU4570:Multi-bit Trie(区间DP)
Problem Description IP lookup is one of the key functions of routers for packets forwarding and clas ...
- 【BZOJ-4380】Myjnie 区间DP
4380: [POI2015]Myjnie Time Limit: 40 Sec Memory Limit: 256 MBSec Special JudgeSubmit: 162 Solved: ...
- 【POJ-1390】Blocks 区间DP
Blocks Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5252 Accepted: 2165 Descriptio ...
- 区间DP LightOJ 1422 Halloween Costumes
http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...
- BZOJ1055: [HAOI2008]玩具取名[区间DP]
1055: [HAOI2008]玩具取名 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1588 Solved: 925[Submit][Statu ...
- poj2955 Brackets (区间dp)
题目链接:http://poj.org/problem?id=2955 题意:给定字符串 求括号匹配最多时的子串长度. 区间dp,状态转移方程: dp[i][j]=max ( dp[i][j] , 2 ...
- HDU5900 QSC and Master(区间DP + 最小费用最大流)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5900 Description Every school has some legends, ...
- 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 ...
- 区间dp总结篇
前言:这两天没有写什么题目,把前两周做的有些意思的背包题和最长递增.公共子序列写了个总结.反过去写总结,总能让自己有一番收获......就区间dp来说,一开始我完全不明白它是怎么应用的,甚至于看解题报 ...
随机推荐
- unable to create new native thread 问题
ulimit -a ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling pr ...
- codeforces 569C C. Primes or Palindromes?(素数筛+dp)
题目链接: C. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes in ...
- storm相关技术
There are two kinds of nodes on a Storm cluster: the master node and the worker nodes. 有两种节点,主节点和wor ...
- AtCoder Regular Contest 070F:Honest Or Unkind
题目传送门:https://arc070.contest.atcoder.jp/tasks/arc070_d 题目翻译 有\(n\)个人,其中有\(a\)个人是诚实的,另外\(b\)个是不诚实的.你可 ...
- Jasper:SAOP API 函数
ylbtech-Jasper:SAOP API 函数 1.设备API返回顶部 1. 设备 设备 API 可以访问详细的设备(SIM 卡)信息,包括当前会话.您也可以更改属性值. API 调用 描述 A ...
- Camera Vision - video surveillance on C#
转自:http://blog.csdn.net/xyz_lmn/article/details/6072897 http://www.codeproject.com/KB/audio-video/ca ...
- node url
var url = require("url") url模块提供的三个方法: url.parse(urlStr[, parseQueryString][, slashesDenot ...
- java.lang.NoClassDefFoundError: org/springframework/dao/support/DaoSupport
转自:https://blog.csdn.net/lzx159951/article/details/79753493 1. 缺少:org.springframework.transaction-3. ...
- iView之select获取value和label
使用:label-in-value="true" @on-change="obtainValue" 详见官方文档:https://www.iviewui.com ...
- HTML5学习笔记(四)语义元素
语义元素能够清楚的描述其意义给浏览器和开发者. 无语义 元素实例: <div> 和 <span> - 无需考虑内容. 语义元素实例: <form>, <tab ...