Multiplication Puzzle

Time Limit: 1000ms
Memory Limit: 65536KB

This problem will be judged on PKU. Original ID: 1651
64-bit integer IO format: %lld      Java class name: Main

 
 
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

 
解题:dp[i][j]表示从i到j被划分后的最小值!为什么dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j]+d[i]*d[j]*d[k])ne
 
举个栗子 1 2 3 4 5
 
dp[1][5] = min(dp[1][5],dp[1][3]+dp[3][5]+d[1]*d[3]*d[5]) dp[i][j]表示i j段 剩有i j,像刚才的转移方程,dp[1][5]不是取了3以后 剩下了1 5 么
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
int dp[][],d[],n;
int main(){
int i,j,k;
while(~scanf("%d",&n)){
for(i = ; i <= n; i++)
scanf("%d",d+i);
memset(dp,,sizeof(dp));
for(k = ; k <= n; k++){
for(i = ; i+k- <= n; i++){
dp[i][i+k-] = INF;
for(j = i+; j < i+k; j++)
dp[i][i+k-] = min(dp[i][i+k-],dp[i][j]+dp[j][i+k-]+d[i]*d[j]*d[i+k-]);
}
}
cout<<dp[][n]<<endl;
}
return ;
}
 

xtu read problem training 4 B - Multiplication Puzzle的更多相关文章

  1. xtu read problem training 3 B - Gears

    Gears Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ID: 3789 ...

  2. xtu read problem training 3 A - The Child and Homework

    The Child and Homework Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on Code ...

  3. xtu read problem training 2 B - In 7-bit

    In 7-bit Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ID: 3 ...

  4. xtu read problem training 4 A - Moving Tables

    Moving Tables Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ...

  5. xtu read problem training B - Tour

    B - Tour Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Descriptio ...

  6. xtu read problem training A - Dividing

    A - Dividing Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Descri ...

  7. poj 1651 Multiplication Puzzle (区间dp)

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

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

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

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

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

随机推荐

  1. UOJ228 简单数据结构练习题

    Description 传送门 维护一个数列, 有以下操作: 对[l,r]同时加上x 把[l,r]开根后下取整. 查询[l,r]之和 n,m \(\leq\)$ 100000, $\(a_i,x \l ...

  2. [Usaco2005 Dec]Knights of Ni 骑士

    Description Bessie is in Camelot and has encountered a sticky situation: she needs to pass through t ...

  3. Median Value

    Problem A: Median Value Time Limit: 1 Sec Memory Limit: 128 MB Submit: 874 Solved: 307 [Submit][Stat ...

  4. Linux环境下HDFS集群环境搭建关键步骤

    Linux环境下HDFS集群环境搭建关键步骤记录. 介质版本:hadoop-2.7.3.tar.gz 节点数量:3节点. 一.下载安装介质 官网下载地址:http://hadoop.apache.or ...

  5. Linux环境下ZooKeeper集群环境搭建关键步骤

    ZooKeeper版本:zookeeper-3.4.9 ZooKeeper节点:3个节点 以下为Linux环境下ZooKeeper集群环境搭建关键步骤: 前提条件:已完成在Linux环境中安装JDK并 ...

  6. 面试王牌 JAVA 多态只针对方法 不针对属性

    子类是永远继承父类的非私有化方法,当子类中重写父类方法时,调用的是子类的方法,没有重写时,调用的是父类中的方法 1 多态是只针对方法,而不是属性的,但是写法上,子类重写父类的属性,编译器是不会报错的 ...

  7. 437 Path Sum III 路径总和 III

    给定一个二叉树,二叉树的每个节点含有一个整数.找出路径和等于给定数的路径总数.路径不需要从根节点开始,也不需要在叶节点结束,当路径方向必须是向下的(只从父节点到子节点).二叉树不超过1000个节点,节 ...

  8. VM virtualBox设置无缝全屏

    设置之前:

  9. greenplum安装札记(待完善)

    1.安装配置 1.1硬件配置 硬件服务器用到某私有云中ip段为192.168.228.111-192.168.228.120的十台服务器,相关主要配置如下表: 类别 主机名 IP 内存 硬盘 主要目录 ...

  10. vue2.0 路由知识一(路由的创建的全过程)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...