POJ1651Multiplication Puzzle[区间DP]
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 8737 | Accepted: 5468 |
Description
The goal is to take cards in such order as to minimize the total number of scored points.
For example, if cards in the row contain numbers 10 1 50 20 5, player might take a card with 1, then 20 and 50, scoring
10*1*50 + 50*20*5 + 10*50*5 = 500+5000+2500 = 8000
If he would take the cards in the opposite order, i.e. 50, then 20, then 1, the score would be
1*50*20 + 1*20*5 + 10*1*5 = 1000+100+50 = 1150.
Input
Output
Sample Input
6
10 1 50 50 20 5
Sample Output
3650
Source
题意:选数字删去,价值为它乘以左右,头尾不能取,求最小价值
裸的矩阵链乘
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=,INF=1e9;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x;
}
int n,a[N],f[N][N];
int main(){
n=read();
for(int i=;i<=n;i++) a[i]=read();
for(int i=n;i>=;i--)
for(int j=i+;j<=n;j++){
f[i][j]=INF;
for(int k=i+;k<=j-;k++)
f[i][j]=min(f[i][j],f[i][k]+f[k][j]+a[i]*a[k]*a[j]);
}
printf("%d",f[][n]);
}
POJ1651Multiplication Puzzle[区间DP]的更多相关文章
- [ZOJ]3541 Last Puzzle (区间DP)
ZOJ 3541 题目大意:有n个按钮,第i个按钮在按下ti 时间后回自动弹起,每个开关的位置是di,问什么策略按开关可以使所有的开关同时处于按下状态 Description There is one ...
- POJ1651:Multiplication Puzzle(区间DP)
Description The multiplication puzzle is played with a row of cards, each containing a single positi ...
- poj 1651 Multiplication Puzzle (区间dp)
题目链接:http://poj.org/problem?id=1651 Description The multiplication puzzle is played with a row of ca ...
- POJ 1651 Multiplication Puzzle 区间dp(水
题目链接:id=1651">点击打开链 题意: 给定一个数组,每次能够选择内部的一个数 i 消除,获得的价值就是 a[i-1] * a[i] * a[i+1] 问最小价值 思路: dp ...
- 区间DP小结
也写了好几天的区间DP了,这里稍微总结一下(感觉还是不怎么会啊!). 但是多多少少也有了点感悟: 一.在有了一点思路之后,一定要先确定好dp数组的含义,不要模糊不清地就去写状态转移方程. 二.还么想好 ...
- POJ1651Multiplication Puzzle(区间DP)
比较好做的区间DP 状态转移方程:DP[i][j] 表示区间[i,j]最小的乘积和. DP[i][j] = MIN{DP[i][k-1]+DP[k+1][j] + a[k]*a[i-1]*a[j+1] ...
- Poj 1651 Multiplication Puzzle(区间dp)
Multiplication Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10010 Accepted: ...
- POJ 1651 Multiplication Puzzle(类似矩阵连乘 区间dp)
传送门:http://poj.org/problem?id=1651 Multiplication Puzzle Time Limit: 1000MS Memory Limit: 65536K T ...
- 区间dp E - Multiplication Puzzle POJ - 1651
E - Multiplication Puzzle POJ - 1651 这个题目没有特别简单,但是也没有我想象之中的那么难,这个题目时区间dp,因为我们是要对区间进行考虑的. 但是呢,这个也和动态 ...
随机推荐
- MontageJS:构建现代 Web App 的 HTML5 框架
MontageJS 可以帮助您构建高可扩展性和可维护性的 HTML5 应用.有了 MontageJS,开发人员可以创建可重用的用户界面组件和模块,组件和控制器之间的绑定属性,并且同步 DOM 查询和更 ...
- about reg
var getR=function(str,reg){ return str.match(reg).join(""); } var a=getR("138888" ...
- react native 学习一(环境搭配和常见错误的解决)
react native 学习一(环境搭配) 首页,按照http://reactnative.cn/docs/0.30/getting-started.html#content上的介绍,下载安装pyt ...
- 关于处理addGiftmoneyAction接口报错问题的总结
昨天UniUser中AddGiftmoneyAction接口在被调用时抛出异常,曾哥让我来解决这个问题,虽然最后查出是路径问题,但是由于解决问题 的思路不够清晰,导致浪费了大量的时间和精力,也没有给出 ...
- mysql win源码比较大 不需要的文件删除 记录下来
mysql-5.6.25-win32.zip 从官方下载下来的大小为 343MB,太大了可以删除掉的地方记录一下 docs :全部删除. sql-bench:全部删除. mysql-test :全部删 ...
- 关于JS堆栈与拷贝
1.栈(stack)和堆(heap) stack为自动分配的内存空间,它由系统自动释放:而heap则是动态分配的内存,大小不定也不会自动释放. 2.基本类型和引用类型 基本类型:存放在栈内存中的简单数 ...
- Jquery属性获取——attr()与prop()
今天在项目中使用<select></select>下拉菜单时,使用juery操作,使页面加载完菜单默认选中的值为2,我一开始的操作如下: <!--html部分--> ...
- 一次失败的APP业务渗透测试
作者:whoamiecho 来源:ichunqiu 本文参加i春秋社区原创文章奖励计划,未经许可禁止转载! 一. 过程 1.1.事情起因:暴力破解 测试给了个普通用户账号,可以登录.APP一来就要登 ...
- 国内最全最详细的hadoop2.2.0集群的MapReduce的最简单配置
简介 hadoop2的中的MapReduce不再是hadoop1中的结构已经没有了JobTracker,而是分解成ResourceManager和ApplicationMaster.这次大变革被称为M ...
- AVAudioSession初探
根据文档,AudioSession规定了app和系统音频行为交互的规范,一个app只有一个AudioSession的单例. app通过设置自己AudioSession的单例的属性来告诉系统自身想达到的 ...