xtu read problem training 4 B - Multiplication Puzzle
Multiplication Puzzle
This problem will be judged on PKU. Original ID: 1651
64-bit integer IO format: %lld Java class name: Main
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
Output
Sample Input
6
10 1 50 50 20 5
Sample Output
3650
Source
#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的更多相关文章
- xtu read problem training 3 B - Gears
Gears Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ID: 3789 ...
- 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 ...
- 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 ...
- xtu read problem training 4 A - Moving Tables
Moving Tables Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ...
- xtu read problem training B - Tour
B - Tour Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Descriptio ...
- xtu read problem training A - Dividing
A - Dividing Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Descri ...
- poj 1651 Multiplication Puzzle (区间dp)
题目链接:http://poj.org/problem?id=1651 Description The multiplication puzzle is played with a row of ca ...
- POJ 1651 Multiplication Puzzle(类似矩阵连乘 区间dp)
传送门:http://poj.org/problem?id=1651 Multiplication Puzzle Time Limit: 1000MS Memory Limit: 65536K T ...
- POJ1651 Multiplication Puzzle —— DP 最优矩阵链乘 区间DP
题目链接:https://vjudge.net/problem/POJ-1651 Multiplication Puzzle Time Limit: 1000MS Memory Limit: 65 ...
随机推荐
- UOJ228 简单数据结构练习题
Description 传送门 维护一个数列, 有以下操作: 对[l,r]同时加上x 把[l,r]开根后下取整. 查询[l,r]之和 n,m \(\leq\)$ 100000, $\(a_i,x \l ...
- [Usaco2005 Dec]Knights of Ni 骑士
Description Bessie is in Camelot and has encountered a sticky situation: she needs to pass through t ...
- Median Value
Problem A: Median Value Time Limit: 1 Sec Memory Limit: 128 MB Submit: 874 Solved: 307 [Submit][Stat ...
- Linux环境下HDFS集群环境搭建关键步骤
Linux环境下HDFS集群环境搭建关键步骤记录. 介质版本:hadoop-2.7.3.tar.gz 节点数量:3节点. 一.下载安装介质 官网下载地址:http://hadoop.apache.or ...
- Linux环境下ZooKeeper集群环境搭建关键步骤
ZooKeeper版本:zookeeper-3.4.9 ZooKeeper节点:3个节点 以下为Linux环境下ZooKeeper集群环境搭建关键步骤: 前提条件:已完成在Linux环境中安装JDK并 ...
- 面试王牌 JAVA 多态只针对方法 不针对属性
子类是永远继承父类的非私有化方法,当子类中重写父类方法时,调用的是子类的方法,没有重写时,调用的是父类中的方法 1 多态是只针对方法,而不是属性的,但是写法上,子类重写父类的属性,编译器是不会报错的 ...
- 437 Path Sum III 路径总和 III
给定一个二叉树,二叉树的每个节点含有一个整数.找出路径和等于给定数的路径总数.路径不需要从根节点开始,也不需要在叶节点结束,当路径方向必须是向下的(只从父节点到子节点).二叉树不超过1000个节点,节 ...
- VM virtualBox设置无缝全屏
设置之前:
- greenplum安装札记(待完善)
1.安装配置 1.1硬件配置 硬件服务器用到某私有云中ip段为192.168.228.111-192.168.228.120的十台服务器,相关主要配置如下表: 类别 主机名 IP 内存 硬盘 主要目录 ...
- vue2.0 路由知识一(路由的创建的全过程)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...