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. URL(统一资源定位符)结构和注意事项

    URL的常见结构: http://localhost/项目名称/文件1/文件2... 注意事项: 当我们在项目中在书写URL的时候,一般会出现两种情况: 第一种:在路径前面加上/,表示直接连在loca ...

  2. Large-file-chunk-size 设置最大文件上传值

    Large-file-chunk-size: Stsadm property (Office SharePoint Server) SharePoint 2007   0 out of 1 rated ...

  3. Android 插件化

    1.介绍 涛哥写的文章  <Android 插件化的 过去 现在 未来> http://kymjs.com/code/2016/05/04/01#rd

  4. Ubuntu 安装Samba服务器

    1.安装 sudo apt-get update sudo apt-get install samba (如果出现库依赖问题可用命令sudo apt-get install samba libwbcl ...

  5. js 判断多个一样的name

    var items = document.getElementsByName("spec_spec_1[]"); alert(items.length); for (i = 0; ...

  6. composer 学习资料

    今天看了一下composer,前几天开始用包依赖,以前一直都是自己手动配.今天用了composer,要学习的话可以按照以下链接学习: 1 官方文档: http://www.phpcomposer.co ...

  7. Scrum Master 面试题 – 你必须知道的22个Scrum基础知识

    以下的22个问题基本上涵盖了Scrum所涉及的内容,如果你能够正确回答出所有问题,那么你已经具备了作为一名Scrum Master的基本素质:当然,作为一名合格的Scrum Master,更重要的是你 ...

  8. Cloud9:解决ThinkPHP在C9上运行时连接数据库时报错"No such file or directory"的问题

    昨天尝试在c9上部署了一个ThinkPHP用于开发,但是当试图连接数据库时却出现了这样的问题.经过查找资料发现此问题是由于没有找到mysql.sock这个文件造成的(这个东西估计是mysql的连接线程 ...

  9. SQL Server 连接超时案例一则

    上周六,一工厂系统管理员反馈一数据库连接不上,SSMS连接数据库报"连接超时时间已到.在尝试使用预登录握手确认时超过了此超时时间.......", 如下截图所示: 另外远程连接也连 ...

  10. [Config]Zabbix的Mongodb插件安装,centos

    1.yum install php-devel php-pear httpd-devel 2.安装mongo php驱动,pecl install mongo 3.pecl install mongo ...