Multiplication Puzzle
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8737   Accepted: 5468

Description

The multiplication puzzle is played with a row of cards, each containing a single positive integer. During the move player takes one card out of the row and scores the number of points equal to the product of the number on the card taken and the numbers on the cards on the left and on the right of it. It is not allowed to take out the first and the last card in the row. After the final move, only two cards are left in the row.

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

The first line of the input contains the number of cards N (3 <= N <= 100). The second line contains N integers in the range from 1 to 100, separated by spaces.

Output

Output must contain a single integer - the minimal score.

Sample Input

6
10 1 50 50 20 5

Sample Output

3650

Source

Northeastern Europe 2001, Far-Eastern Subregion

题意:选数字删去,价值为它乘以左右,头尾不能取,求最小价值

裸的矩阵链乘
f[i][j]=min(f[i][j],f[i][k]+f[k][j]+a[i]*a[k]*a[j]);
f[i][i+1]不能初始化为INF
#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]的更多相关文章

  1. [ZOJ]3541 Last Puzzle (区间DP)

    ZOJ 3541 题目大意:有n个按钮,第i个按钮在按下ti 时间后回自动弹起,每个开关的位置是di,问什么策略按开关可以使所有的开关同时处于按下状态 Description There is one ...

  2. POJ1651:Multiplication Puzzle(区间DP)

    Description The multiplication puzzle is played with a row of cards, each containing a single positi ...

  3. poj 1651 Multiplication Puzzle (区间dp)

    题目链接:http://poj.org/problem?id=1651 Description The multiplication puzzle is played with a row of ca ...

  4. POJ 1651 Multiplication Puzzle 区间dp(水

    题目链接:id=1651">点击打开链 题意: 给定一个数组,每次能够选择内部的一个数 i 消除,获得的价值就是 a[i-1] * a[i] * a[i+1] 问最小价值 思路: dp ...

  5. 区间DP小结

    也写了好几天的区间DP了,这里稍微总结一下(感觉还是不怎么会啊!). 但是多多少少也有了点感悟: 一.在有了一点思路之后,一定要先确定好dp数组的含义,不要模糊不清地就去写状态转移方程. 二.还么想好 ...

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

  7. Poj 1651 Multiplication Puzzle(区间dp)

    Multiplication Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10010   Accepted: ...

  8. POJ 1651 Multiplication Puzzle(类似矩阵连乘 区间dp)

    传送门:http://poj.org/problem?id=1651 Multiplication Puzzle Time Limit: 1000MS   Memory Limit: 65536K T ...

  9. 区间dp E - Multiplication Puzzle POJ - 1651

    E - Multiplication Puzzle  POJ - 1651 这个题目没有特别简单,但是也没有我想象之中的那么难,这个题目时区间dp,因为我们是要对区间进行考虑的. 但是呢,这个也和动态 ...

随机推荐

  1. ARCGIS server没有服务、silverlight不能调试、windows server2008安装时跳出“安装程序无法创建新的系统分区也无法定位现有的系统分区”的解决方案

    1.某个系统服务没开启 2.默认浏览器设置为IE.(IE内核有时候也不能调试) 3.BIOS里面的SATA设置为开启.

  2. 编译安装mysql(Ubuntu10 64位)

    选用较好的编译器和较好的编译器选项,这样应用可提高性能10-30%,这个对大多数程序都非常重要 Mysql的编译,不同的版本具体的配置方式是有差别的 旧版的配置形式参考 这个形式主要是使用config ...

  3. UIButton的titleEdgeInsets属性和imageEdgeInsets属性实现图片文字按要求排列

    button可以设置 titleEdgeInsets属性和 imageEdgeInsets属性来调整其image和label相对位置,具体参考http://stackoverflow.com/ques ...

  4. iOS开发之动画中的时间

    概述 在动画中,我们会指定动画的持续时间.例如 scaleAnimation.duration = self.config.appearDuration 那么这个时间是怎么定义的呢?是指的绝对时间吗? ...

  5. JavaScript上传图片及时预览

    /*******************************正面图片上传预览开始****************************/        function previewImage ...

  6. objective-c系列-@Property&点语法

    //解释 property后边的圆括号中的修饰词的含义: //          nonatomic  非线程安全  非原子操作  特点是: 操作变量的效率高 //          atomic   ...

  7. 【代码笔记】iOS-等待动画

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

  8. C阶段【01】 - C基础

    一.进制 进位方法:逢几进一(也就是几进制) 举例:十进制 12  :  二进制  0b(计算机前缀)  0b1011  :  八进制  0   073  :十六进制  0x  0xABCDEF 十进 ...

  9. 豆瓣FM 歌词跟随插件

    一直在用豆瓣FM,发现老是没有歌词很不方便,今天找了下.找到一个不错的插件. 插件原文地址:http://www.douban.com/group/topic/47559280/ 插件下载地址:htt ...

  10. HTML页面禁止选择、页面禁止复制、页面禁止右键

    HTML页面内容禁止选择.复制.右键刚在一个看一个站点的源代码的的时候发现的,其实原来真的很简单 <body leftmargin=0 topmargin=0 oncontextmenu='re ...