Multiplication Puzzle
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7252   Accepted: 4478

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,挺简单的。
给你一组数字,第一个和最后一个数字不可以取出去,其它任意取出去,当你要取出一个数字时,它有一个代价,这个代价就是与它相邻的两个数的乘积,求除了首位两位数字,把其他数字都取出来,它们的代价之和的最小值........
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define ll long long
#define _cle(m, a) memset(m, a, sizeof(m))
#define repu(i, a, b) for(int i = a; i < b; i++)
#define repd(i, a, b) for(int i = b; i >= a; i--)
#define sfi(n) scanf("%d", &n)
#define pfi(n) printf("%d\n", n)
#define sfi2(n, m) scanf("%d%d", &n, &m)
#define pfi2(n, m) printf("%d %d\n", n, m)
#define pfi3(a, b, c) printf("%d %d %d\n", a, b, c)
#define MAXN 105
const int INF = 0x3f3f3f3f;
int a[MAXN];
int dp[MAXN][MAXN];
int main()
{
int n;
while(~sfi(n))
{
repu(i, , n) sfi(a[i]);
_cle(dp, 0x3f);
dp[][] = a[];
a[n + ] = ;
repu(i, , n + ) dp[i][i] = a[i - ] * a[i] * a[i + ];
repu(i, , n) repu(j, , i) dp[i][j] = ;
for(int i = n - ; i > ; i--)
repu(j, i + , n) repu(k, i, j + )
dp[i][j] = min(dp[i][j], dp[i][k - ] + a[k] * a[i - ] * a[j + ] + dp[k + ][j]);
pfi(dp[][n - ]);
}
return ;
}

poj1651的更多相关文章

  1. POJ1651 Multiplication Puzzle —— DP 最优矩阵链乘 区间DP

    题目链接:https://vjudge.net/problem/POJ-1651 Multiplication Puzzle Time Limit: 1000MS   Memory Limit: 65 ...

  2. poj1651 区间dp

    //Accepted 200 KB 0 ms //dp区间 //dp[i][j]=min(dp[i][k]+dp[k][j]+a[i]*a[k]*a[j]) i<k<j #include ...

  3. POJ1651:Multiplication Puzzle(区间DP)

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

  4. poj1651 最优矩阵乘法动态规划解题

    题目描述: 有若干个矩阵{Ai},元素都为整数且已知矩阵大小. 如果要计算所有矩阵的乘积A1 * A2 * A3 .. Am,最少要多少次整数乘法? 输入 第一行一个整数n(n <= 100), ...

  5. poj1651(区间dp)

    题目连接:http://poj.org/problem?id=1651 题意:给出一组N个数,每次从中抽出一个数(第一和最后一个不能抽),该次的得分即为抽出的数与相邻两个数的乘积.直到只剩下首尾两个数 ...

  6. POJ1651(KB-E)

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

  7. poj1651 Multiplication Puzzle

    比较特别的区间dp.小的区间转移大的区间时,也要枚举断点.不过和普通的区间dp比,断点有特殊意义.表示断点是区间最后取走的点.而且一个区间表示两端都不取走时中间取走的最小花费. #include &l ...

  8. POJ1651 Multiplication Puzzle【区间DP】

    LINK 每次删除一个数,代价是左右两边相邻的数的当前数的积 第一个和最后一个数不能删除 问最后只剩下第一个数的最后一个数的最小代价 思路 很简单的DP 正着考虑没有办法确定两边的数 那么就把每个区间 ...

  9. POJ1651 Multiplication Puzzle(相邻乘积之和最小,区间DP)

    http://blog.csdn.net/libin56842/article/details/9747021 http://www.cnblogs.com/devil-91/archive/2012 ...

随机推荐

  1. C# 导出数据至 CSV

    有时候将Excel的数据另存到csv文件会出现csv格式错误,以下示例实现将DataTable里面的数据直接保存到csv文件. System.Web.HttpRuntime.Cache["v ...

  2. zoj 1010 (线段相交判断+多边形求面积)

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=10 Area Time Limit: 2 Seconds      Mem ...

  3. check running processes in Ubuntu

    Check processes If you want to see what processes are running use the command ps -ef If you want to ...

  4. hdu 5693 朋友 博弈

    朋友 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Descr ...

  5. svn使用(服务器端和客户端)

    http://www.cnblogs.com/tugenhua0707/p/3969558.html 网址如上. 很详细.

  6. mypc--------------->lspci,lsusb,meminfo cpuinfo ioports filesystems interrupts mounts net partitions pagetypeinfo slabinfo timer_list uptime version zoneinfo 等配置信息

    [user@username home]$ lspci00:00.0 Host bridge: Intel Corporation 4th Gen Core Processor DRAM Contro ...

  7. OpenERP QWeb模板标签笔记

    在OpenERP中,通过QWeb来对模板进行渲染后加载到浏览器中,而模板中有许多的标签来定制各种需求变化,在这里记录学习过程中碰到的标签定义,以方便查询. 模板中的标签统一都是以"t-&qu ...

  8. JS常用方法函数

    document.write("");为 输出语句    2.JS中的注释为//    3.传统的HTML文档顺序是:document->html->(head,bod ...

  9. JavaSE复习_6 枚举类

    △单例类是指只有一个实例,而枚举类实际上就是有有限个实例的类,在类里已经把实例定义好了. △枚举类的三种创建形式: 1) enum Week { MON,TUE,WED;//枚举类有默认构造函数创建的 ...

  10. 最大的LeftMax与rightMax之差绝对值

    这两天去 牛客网 混了下,遇到的几道题都很有意思,尤其是今晚这道,比赛时不会做,后来看了别人的代码才突然想通的,题目链接: 最大的LeftMax与rightMax之差绝对值,大意是: 想了一晚都没想出 ...