这道题的题意不是一般的难懂啊,各种查字典都没理解,还是没忍住去看了别人的博客,没想到题很简单,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的更多相关文章

  1. 【hdu4570】Multi-bit Trie 区间DP

    标签: 区间dp hdu4570 http://acm.hdu.edu.cn/showproblem.php?pid=4570 题意:这题题意理解变态的.转自大神博客: 这题题意确实有点难懂,起码对于 ...

  2. HDU4570:Multi-bit Trie(区间DP)

    Problem Description IP lookup is one of the key functions of routers for packets forwarding and clas ...

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

  10. 区间dp总结篇

    前言:这两天没有写什么题目,把前两周做的有些意思的背包题和最长递增.公共子序列写了个总结.反过去写总结,总能让自己有一番收获......就区间dp来说,一开始我完全不明白它是怎么应用的,甚至于看解题报 ...

随机推荐

  1. spring2.5整合struts2

    首先第一步: 导入jar包: 我的做法: 导入你的基本使用的spring的jar包 和基本使用的struts2的jar包 然后struts2中有一个和spring整合的jar包一定要导入,不然会抛异常 ...

  2. listen 55

    There are also green card qualifiers for some non-citizens who invest in America, and for refugees.难 ...

  3. codeforces 566D D. Restructuring Company(并查集)

    题目链接: D. Restructuring Company time limit per test 2 seconds memory limit per test 256 megabytes inp ...

  4. 【Lintcode】046.Majority Number

    题目: Given an array of integers, the majority number is the number that occurs more than half of the ...

  5. 恋恋风辰 对于redis底层框架的理解(一)

    近期学习了redis底层框架,好多东西之前都没听说过,算是大开眼界了. 先梳理下redis正常的通讯流程吧 首先服务器启动都有主函数main,这个main函数就在redis.c里 首先是initser ...

  6. 洛谷P1352——动规

    题目:https://www.luogu.org/problemnew/show/P1352 代码如下: #include<iostream> #include<cstdio> ...

  7. C# 对象间的 深拷贝 实现

        以下的这个类实现了 2个含有部分字段名字相同 的对象的 赋值拷贝. public class ShallowCopyHelper     {         public static voi ...

  8. fabric添加多主机ssh互信

    最近折腾fabric,把服务器ssh互信用fabric写了一遍,单向互信,master可以无密码访问client,具体如下: 执行:fab  -f ./copyrsa.py allsshkey 即可, ...

  9. Deepin安装wxpython教程

    环境: 安装报错: 解决:  1.sudo apt-get install libgtk-3-dev -y 2.sudo apt-get install freeglut3-dev libgstrea ...

  10. angular学习的一些Mark

    http://www.cnblogs.com/xianrongbin/p/4104596.html http://angular-ui.github.io/