POJ1651:Multiplication Puzzle(区间DP)
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
题意:一系列的数字,除了头尾不能动,每次取出一个数字,这个数字与左右相邻数字的乘积为其价值,最后将所有价值加起来,要求最小值
思路:求出每个区间的最小值,一直扩散到整个区间
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; int n,a[105],dp[105][105],i,j,k,l; int main()
{
while(~scanf("%d",&n))
{
for(i = 1; i<=n; i++)
scanf("%d",&a[i]);
memset(dp,0,sizeof(dp));
for(l = 2; l<n; l++)//长度从2开始枚举
{
for(i = 2; i+l<=n+1; i++)
{
j = i+l-1;
dp[i][j] = 100000000;
for(k = i; k<j; k++)//枚举中点
dp[i][j] = min(dp[i][j],dp[i][k]+dp[k+1][j]+a[i-1]*a[k]*a[j]);
}
}
printf("%d\n",dp[2][n]);
} return 0;
}
POJ1651:Multiplication Puzzle(区间DP)的更多相关文章
- 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 ...
- POJ1651 Multiplication Puzzle —— DP 最优矩阵链乘 区间DP
题目链接:https://vjudge.net/problem/POJ-1651 Multiplication Puzzle Time Limit: 1000MS Memory Limit: 65 ...
- POJ1651:Multiplication Puzzle(区间dp)
Multiplication Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9419 Accepted: 5850 ...
- [ZOJ]3541 Last Puzzle (区间DP)
ZOJ 3541 题目大意:有n个按钮,第i个按钮在按下ti 时间后回自动弹起,每个开关的位置是di,问什么策略按开关可以使所有的开关同时处于按下状态 Description There is one ...
- POJ1651Multiplication Puzzle[区间DP]
Multiplication Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8737 Accepted: ...
- poj1651 Multiplication Puzzle
比较特别的区间dp.小的区间转移大的区间时,也要枚举断点.不过和普通的区间dp比,断点有特殊意义.表示断点是区间最后取走的点.而且一个区间表示两端都不取走时中间取走的最小花费. #include &l ...
- POJ1651 Multiplication Puzzle【区间DP】
LINK 每次删除一个数,代价是左右两边相邻的数的当前数的积 第一个和最后一个数不能删除 问最后只剩下第一个数的最后一个数的最小代价 思路 很简单的DP 正着考虑没有办法确定两边的数 那么就把每个区间 ...
- poj1651 Multiplication Puzzle(简单区间dp)
题目链接:http://poj.org/problem?id=1651 题意:一系列的数字,除了头尾不能动,每次取出一个数字,这个数字与左右相邻数字的乘积为其价值, 最后将所有价值加起来,要求最小值. ...
随机推荐
- 各种边框样式。。本以为border不是这么用的。
关于文本框样式□ 文本框样式 □ 显示虚线边框的文本框(IE5.5才可看到效果) <INPUT style="border-width: 1px,1px,1px,1px;border ...
- 转】MySQL客户端输出窗口显示中文乱码问题解决办法
原博文出自于: http://www.cnblogs.com/xdp-gacl/p/4008095.html 感谢! 最近发现,在MySQL的dos客户端输出窗口中查询表中的数据时,表中的中文数据都显 ...
- 简单版问卷调查系统(Asp.Net+SqlServer2008)
1.系统主要涉及以下几个表 问卷项目表(Q_Naire) 问卷题目表(Q_Problem) 题目类型表(Q_ProblmeType) 题目选项表(Q_Options) 调查结果表(Q_Answer) ...
- VISA资源名称控件
NI-VISA能自动检测端口.通过前面板上的VISA资源名称控件或VISA查找资源函数可查看端口列表.在任何平台上,NI-VISA支持的最大串口数量为256,串口的默认数量取决于操作系统. VISA资 ...
- iOS多线程总结
1.不要同时开太多的线程(1~3条线程即可,不要超过5条) 2.线程概念 1> 主线程 : UI线程,显示.刷新UI界面,处理UI控件的事件 2> 子线程 : 后台线程,异步线程 3.不要 ...
- spring事物配置注意事项
<tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx ...
- Java和MongoDB之Hello World
1.新建Project 新建Java Project,并把mongo-java-driver驱动加入到项目bulid path中,如果你使用的是maven增加依赖. <dependency> ...
- mac 安装PIL
PIL是python Image library 在mac终端中通过以下命令安装: # download curl -O -L http://effbot.org/media/downloads/Im ...
- 常见Java基础知识(较长)
1.抽象: 抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面.抽象并不打算了解全部问题,而只是选择其中的一部分,暂时不用部分细节.抽象包括两个方面,一是过程抽象, ...
- Objc中2维指针作为输出参数时由ARC及@autoreleasepool引发的血案
先看下面一个例子 #import <UIKit/UIKit.h> #import "AppDelegate.h" @interface Something : NSOb ...