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. Windows API函数大全一

    1. API之网络函数             WNetAddConnection 创建同一个网络资源的永久性连接             WNetAddConnection2 创建同一个网络资源的连 ...

  2. AJPFX关于TreeSet集合的介绍

    需求:键盘录入5个学生信息(姓名,语文成绩,数学成绩,英语成绩),按照总分从高到低输出到控制台.分析:1.创建键盘录入对象:          2.创建TreeSet集合,使用匿名内部类实现Compa ...

  3. AJPFX总结final、finally、finallize的区别

    final.finally.finallize有何区别?    final表示一个修饰符,如果用它来修饰一个类,则该类是不能继承的:如果用它来修饰一个变量,则该变量一旦赋值之后就不能再修改:如果用它来 ...

  4. 一个简单的公式——求小于N且与N互质的数的和

    首先看一个简单的东西. 若$gcd(i,n)=1$,则有$gcd(n-i,n)=1$ 于是在小于$n$且与$n$互质的数中,$i$与$n-i$总是成对存在,且相加等于$n$. 考虑$i=n-i$的特殊 ...

  5. SSH---整合Struts2&Spring&Hibernate(实例)

    一.SSH回顾 Struts2:核心为过滤器+拦截器.过程:Filter--->FilterDispatcher-->ActionMapper-->ActionProxy--> ...

  6. Spring data jpa中Query和@Query分别返回map结果集

    引用: http://blog.csdn.net/yingxiake/article/details/51016234 http://blog.csdn.net/yingxiake/article/d ...

  7. 机器学习-Probabilistic interpretation

    Probabilistic interpretation,概率解释  解释为何线性回归的损失函数会选择最小二乘 表示误差,表示unmodeled因素或随机噪声,真实的y和预测出来的值之间是会有误差的, ...

  8. web调用手机相册,并实现动态增加图片功能

    注:经测试h5调用相册效果有兼容性问题,安卓仅能调用拍照功能(部分安卓可能会调不起来,所以建议用app原生调用),ios可调起拍照和相册功能. <html xmlns="http:// ...

  9. 中国版 Office 365 (X-Tenant / Tango) 功能验证报告 - 1 简介

    花了点时间做了一次Office 365 X-Tenant的 POC,对过程做了记录和总结,在这里会陆续分享: (一) 简介 这次POC的系统环境是模拟一个公司的生产环境: 1. 公司总部在国外,拥有 ...

  10. xamarin 学习笔记02- IOS Simulator for windows 安装

    微软发布了在window下的ios模拟器 下载 ios模拟器 并安装在windows系统上. Xamarin for Visual Studio 和 网络上的 Mac 中的 Xamarin.iOS 开 ...