cdoj 1131 男神的礼物 区间dp
男神的礼物
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://acm.uestc.edu.cn/#/problem/show/1131
Description
Lweb学长可是会魔法的哟。为了准备一份礼物,男神要加工n份材料。每一次只能加工相邻的材料。
当男神加工两个魔法值为a,b的材料,男神都要消耗a*b的体力,同时在这个地方合成出魔法值(a+b)0的材料。
男神为了能节省体力来完成他的礼物。想找聪明的你帮他算一算他所要花费的最小体力。
Input
Output
每组数据一行输出,表示男神制作这份礼物所要的最小体力。
Sample Input
2
2
18 19
3
40 60 20
Sample Output
342
2400
HINT
对于样例 2:
先加工材料40和60,得到0的材料,消耗40∗60体力,共消耗2400体力;
再加工材料0和20,得到20的材料,消耗0∗20体力,共消耗2400体力.
题意
题解:
区间dp,类似于石子合并的问题,每次每枚举合并的点就好了
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
const int inf=0x7fffffff; //нчоч╢С
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** ll dp[][];
ll a[];
ll sum[];
int main()
{
int t=read();
while(t--)
{
memset(dp,,sizeof(dp));
memset(sum,,sizeof(sum));
int n=read();
for(int i=;i<=n;i++)
{
a[i]=read();
sum[i]=a[i]+sum[i-];
}
for(int r=;r<=n;r++)
{
for(int i=r-;i>=;i--)
{
for(int j=i;j<=r;j++)
{
ll kiss=((sum[j]-sum[i-])%)*((sum[r]-sum[j])%);
if(dp[i][r]==)
dp[i][r]=dp[i][j]+dp[j+][r]+kiss;
else
dp[i][r]=min(dp[i][r],dp[i][j]+dp[j+][r]+kiss);
}
}
} cout<<dp[][n]<<endl;
}
}
cdoj 1131 男神的礼物 区间dp的更多相关文章
- UESTC 2015dp专题 A 男神的礼物 区间dp
男神的礼物 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/65 Descri ...
- [动态规划] uestc oj A - 男神的礼物
A - 男神的礼物 Time Limit: 3000/3000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Lweb学长 ...
- UESTC_男神的礼物 2015 UESTC Training for Dynamic Programming<Problem A>
A - 男神的礼物 Time Limit: 3000/3000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit ...
- cdoj 1134 男神的约会 状压dp
题目链接 给一个10*10的方格, 每个格子里面有0-9,走到一个格子, 就要在这个格子待一段时间, 时间长度为这个格子的数字. 从左上角走到右下角, 要求0-9必须每种格子都要走到, 输出最短时间. ...
- cdoj 1141 酱神寻宝 状压dp
酱神寻宝 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/1141 Descri ...
- 区间DP的学习(持续更新)
例题: 1.Multiplication Puzzle 原题地址:http://poj.org/problem?id=1651 2.Dire Wolf 原题地址:http://acm.split.hd ...
- 男神的约会(状压dp)
有一天男神约了学姐姐去看电影,电影院有一个活动,给你一个10*10的矩阵,每一个格子上都有一个0-9的整数,表示一共十种优惠券中的一种. 观众从左上角的格子开始走,走到右下角.每走到一个有着a号优惠券 ...
- [dp][uestc oj]J - 男神的约会
J - 男神的约会 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit ...
- [kuangbin带你飞]专题二十二 区间DP
ID Origin Title 17 / 60 Problem A ZOJ 3537 Cake 54 / 105 Problem B LightOJ 1422 Hallowee ...
随机推荐
- C#调用其它语言(例如C++)DLL文件中函数的方法摘要
有托管和非托管的概念没仔细看,接下来记录的引用Dll文件指的是无法通过VS自动完成添加引用的情况,可以使用如下方法: 步骤一: 打开“Visual Studio Tools”的“命令提示符”工具 使用 ...
- Eclipse + Idea + Maven + Scala + Spark +sbt
http://jingpin.jikexueyuan.com/article/47043.html 新的scala 编译器idea使用 https://www.jetbrains.com/idea/h ...
- MFC中TRACE
错误 1 error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shar ...
- (转载)OC学习篇之---Foundation框架中的NSObject对象
前一篇文章讲到了OC中的代理模式,而且前几篇文章就介绍了OC中的类相关知识,从这篇文章开始我们开始介绍Foundation框架. OC中的Foundation框架是系统提供了,他就相当于是系统的一套a ...
- MyEclipse10导入工程jsp报错问题
好多时候,再用myecplise进行项目开发的时候,遇到导入工程的时候,工程内的jsp页面好多都报错.这是什么原因造成的呢? 我对于我遇到的问题及解决方法,跟大家分享一下. 我的Jsp页面报错的原 ...
- [翻译]HTML中不知名的语义标签
原文:http://docs.webplatform.org/wiki/tutorials/Lesser_-_known_semantic_elements HTML5中比较常用的语义元素有heade ...
- 图书简介:Spring Batch批处理框架
大数据时代批处理利器,国内首度原创解析Spring Batch框架. 内容简介: <Spring Batch 批处理框架>全面.系统地介绍了批处理框架Spring Batch,通过详尽的实 ...
- the behavior of the UICollectionViewFlowLayout is not defined because:
the behavior of the UICollectionViewFlowLayout is not defined because: the item height must be le ...
- Cloud_panel
传统基础架构应用程序的系统架构师,云计算应用程序的设计确实是相当有挑战性的工作.体现在应用程序架构师首先要了解云计算环境和传统基础架构的差异并且充分利用云计算平台的一些特点来更好的满足用户需求. 对于 ...
- django1.77+mod_wsgi+python2.79+apache2.24 在阿里云centos部署攻略
心平气和的记录一下今天 踩的坑以防万一 以后还踩 首先我今天的平台是在 阿里云上的一台纯净版的 centos6.5 64位主机上进行的 首先装python2.7 去官网下载python2.7安装包 然 ...