传送门:http://poj.org/problem?id=1651

Multiplication Puzzle
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 13109   Accepted: 8034

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
题目意思:
给你一串数字,头尾不能动,每次取出一个数字,这个数字贡献=该数字与左右相邻数字的乘积,求一个最小值。
分析:
是一个区间dp问题,类似矩阵连乘的做法,也是需要在一个区间中选择一个k值从而来达到你的某种要求,这里是要使得消去的值最小
概况一下题意就是:
初使ans=0,每次消去一个值,位置在pos(pos!=1 && pos !=n)
同时ans+=a[pos-1]*a[pos]*a[pos+1],一直消元素直到最后剩余2个,求方案最小的ans是多少?
#include <iostream>
#include<algorithm>
#include <cstdio>
#include<cstring>
using namespace std;
#define max_v 105
#define INF 9999999
int a[max_v];
int dp[max_v][max_v];
int main()
{int n;while(~scanf("%d",&n)){for(int i=1;i<=n;i++){scanf("%d",&a[i]);}memset(dp,0,sizeof(dp));for(int r=2;r<n;r++){for(int i=2;i<=n-r+1;i++){int j=i+r-1;int t=INF;for(int k=i;k<=j-1;k++){t=min(t,dp[i][k]+dp[k+1][j]+a[i-1]*a[k]*a[j]);}dp[i][j]=t;}}printf("%d\n",dp[2][n]);}return 0;
}

转载于:https://www.cnblogs.com/yinbiao/p/9415933.html

POJ 1651 Multiplication Puzzle(类似矩阵连乘 区间dp)相关推荐

  1. POJ - 1651 Multiplication Puzzle (区间dp)

    题目链接:Multiplication Puzzle 定义状态dp[i][j]表示将区间[i, j]全部取完所需要的最小代价,答案就是dp[1][n - 2]. 状态转移方程为:dp[i][j] = ...

  2. poj - 1651 Multiplication Puzzle

    简单DP,矩阵相乘,这次尝试自己写一个,居然过了,很好.本来今天还水了poj 1088 二维空间最长下降(上升)序列和 poj 3624 超水0,1背包,也想贴出来凑数的,可是zxpn同志说,这么水的 ...

  3. POJ 1651 Multiplication Puzzle 区间dp(水

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

  4. 【POJ - 1651】Multiplication Puzzle(区间dp)

    题干: The multiplication puzzle is played with a row of cards, each containing a single positive integ ...

  5. 动态规划训练8 [E - Multiplication Puzzle POJ1651]

    Multiplication Puzzle POJ - 1651 题意: 在一个序列中,拿走一个数字,那么得分就是这个数字以及它相邻的两个数字,这三个数字的乘积.求最小得分. 这道题乍一看感觉是区间D ...

  6. 【动态规划】区间DP - 最优矩阵链乘(另附POJ1651Multiplication Puzzle)

    最优矩阵链乘(动态规划) 一个n∗mn*mn∗m的矩阵由 nnn 行 mmm 列共 n∗mn*mn∗m 排列而成.两个矩阵A和B可以相乘当且仅当A的列数等于B的行数.一个nm的矩阵乘mp的矩阵,运算量 ...

  7. poj 1651区间dp

    poj 1651 题意:给出一个序列,要求取走序列中出首尾之外的数字,问最小花费.取走第k个的花费a[k-1]*a[k]*a[k+1]. //#include<bits/stdc++.h> ...

  8. 【区间DP+高精】codevs1166 矩阵取数游戏题解

    转自: [ametake版权所有]http://blog.csdn.net/ametake欢迎来看 http://blog.csdn.net/ametake/article/details/47664 ...

  9. 【日常学习】【区间DP+高精】codevs1166 矩阵取数游戏题解

    题目来自NOIP2007TG3 如果在考场上我现在已经歇菜了吧 今天一整天的时间全部投在这道题上,收获不小. 先上题目 题目描述 Description [问题描述] 帅帅经常跟同学玩一个矩阵取数游戏 ...

最新文章

  1. 影响了一代代前端人的 20 个里程碑式的顶级开源项目!- 2006 - 2021
  2. linux重启终端后go命令,Linux基础命令之关机,重启,注销-Go语言中文社区
  3. Python基本图形绘制之“蟒蛇绘制”
  4. 利用MRT进行Modis NDVI数据(MOD13Q1)投影变换格式转换操作图文教程
  5. 如何用python打印田字格_如何用 3D 打印一双顶级跑鞋回形针
  6. Hammer.js分析(三)——input.js
  7. 如何用手机打开dcm格式图片_实现原始Dicom自动转换BIDS格式 ——Heudiconv
  8. Python数据类型(元组、列表、字符串、字典)
  9. Leetcode每日一题:183.customers-who-never-order(从不订购的客户)
  10. LCIS最长公共上升子序列
  11. 给龙芯的OpenJDK8升级
  12. Windows游戏编程大师技巧(第2版)
  13. bash脚本运行报错问题原因及解决方法
  14. 利用Hessian矩阵的Frangi 滤波器-python版本
  15. YOLO ZOO:YOU ONLY LOOK ONCE ZOO
  16. Python开发实习心得~
  17. 计算机在职博士要考吗,在职博士容易考吗?
  18. P2573 [SCOI2012]滑雪
  19. 如何给文件夹加密【转】
  20. 2021年深圳市公交线网和地铁线网数据

热门文章

  1. 【CodeForces - 701D】As Fast As Possible(二分,模拟,数学公式)
  2. app android de,Android Deobfuscation
  3. oracle排名怎么去除空值影响,Oracle排序中null值处理方法讲解
  4. html 表格文字颜色 css,CSS 表格-JavaScript中文网-JavaScript教程资源分享门户
  5. roaringbitmap java,roaringbitmap 源码解析 bitmap add过程
  6. 20个常用的正则表达式
  7. Eclipse 中修改java编译版本
  8. leetcode115 不同的子序列
  9. 网游服务器端设计思考:心跳设计
  10. C++(15)--面向对象编程实践-欢乐斗地主(vector的花式输出)