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
题解:区间DP。枚举中间点。
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<cstdlib>
#include<set>
using namespace std;
const int INF=0x3f3f3f3f;
int N,a[],dp[][]; int main()
{
while(scanf("%d",&N)!=EOF)
{
for(int i=;i<=N;i++) scanf("%d",a+i);
memset(dp,,sizeof dp); for(int l=;l<=N-;l++)
{
for(int i=;i<=N-l+;i++)
{
dp[i][i+l-]=INF;
for(int k=i;k<i+l-;k++) dp[i][i+l-]=min(dp[i][i+l-],dp[i][k]+dp[k+][i+l-]+a[i-]*a[k]*a[i+l-]);
}
}
printf("%d\n",dp[][N]);
}
return ;
}

POJ 1651 Mulitiplication Puzzle的更多相关文章

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

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

  2. poj 1651 Multiplication Puzzle (区间dp)

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

  3. poj 1651 Multiplication Puzzle

    题目链接:http://poj.org/problem?id=1651 思路:除了头尾两个数不能取之外,要求把所有的数取完,每取一个数都要花费这个数与相邻两个数乘积的代价,需要这个代价是最小的 用dp ...

  4. poj 1651 Multiplication Puzzle【区间DP】

    题目链接:http://poj.org/problem? id=1651 题意:初使ans=0,每次消去一个值,位置在pos(pos!=1 && pos !=n) 同一时候ans+=a ...

  5. POJ 1651 Multiplication Puzzle (区间DP)

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

  6. Poj 1651 Multiplication Puzzle(区间dp)

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

  7. POJ 1651 Multiplication Puzzle 区间dp(水

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

  8. POJ 1651 Multiplication Puzzle (区间DP,经典)

    题意: 给出一个序列,共n个正整数,要求将区间[2,n-1]全部删去,只剩下a[1]和a[n],也就是一共需要删除n-2个数字,但是每次只能删除一个数字,且会获得该数字与其旁边两个数字的积的分数,问最 ...

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

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

随机推荐

  1. AI的真实感

    目录 1.让AI"不完美"--估算和假设 2 AI感知 全能感知 特定感觉无知 3 AI的个性 4 AI的预判 5 AI的智能等级 ​ AI的真实感一直是游戏AI程序员追求的目标, ...

  2. Hybrid App: 看看第三方WebViewJavascriptBridge是如何来实现Native和JavaScript交互

    一.简介 在前面两篇文章中已经介绍了Native与JavaScript交互的几种方式,依次是JavaScriptCore框架.UI组件UIWebView.WebKit框架,这几种方式都是苹果公司提供的 ...

  3. 多线程-等待(Wait)和通知(notify)

    1.为了支撑多线程之间的协作,JDK提供了两个非常重要的线程接口:等待wait()方法和通知notify()方法. 这两个方法并不是在Thread类中的,而是输出在Object类.这意味着任何对象都可 ...

  4. thinkphp 比RBAC更好的权限认证方式(Auth类认证)

    Auth 类已经在ThinkPHP代码仓库中存在很久了,但是因为一直没有出过它的教程, 很少人知道它, 它其实比RBAC更方便 . RBAC是按节点进行认证的,如果要控制比节点更细的权限就有点困难了, ...

  5. Go 多变量赋值时注意事项

    说到多变量赋值时,先计算所有相关值,然后再从左到右依次赋值,但是这个规则不适用于python我们来看一例: package main import "fmt" func main( ...

  6. 附009.Kubernetes永久存储之GlusterFS独立部署

    一 前期准备 1.1 基础知识 Heketi提供了一个RESTful管理界面,可以用来管理GlusterFS卷的生命周期.Heketi会动态在集群内选择bricks构建所需的volumes,从而确保数 ...

  7. centos安装后第一次重启,许可协议、Kdump

    1.许可协议,服务器键盘操作找到许可 确定(遇到过,第一次懵逼了) 2.Kdump是RHEL提供的一个崩溃转储功能,用于在系统发生故障时提供分析数据,它会占用系统内存,一般选择关闭(默认是关闭)(这个 ...

  8. F#周报2019年第47期

    新闻 相遇WebWindow,.NET Core上的跨平台webview类库 使用Bolero在WebAssembly中运行F# 用于你团队代码库的AI辅助IntelliSense Jupyter N ...

  9. 页面加载和图片加载loading

    准备放假了!也是闲着了 ,就来整理之前学到或用到的一下知识点和使用内容,这次记录的是关于加载的友好性loading!!!这里记录一下两种加载方法 1.页面加载的方法,它需要用到js里面两个方法 doc ...

  10. MySQL索引长度限制

    索引 TextField是不支持建立索引的 MySQL对索引字段长度有限制 innodb引擎的每个索引列长度限制为767字节(bytes),所有组成索引列的长度和不能大于3072字节 myisam引擎 ...