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 ...
随机推荐
- codeforces 555B Case of Fugitive
题目连接: http://codeforces.com/problemset/problem/555/B 题目大意: 有n个岛屿(岛屿在一列上,可以看做是线性的,用来描述岛屿位置的是起点与终点),m个 ...
- [转]C# 邮箱验证激活
原文链接 /// <summary> /// 发送邮件 发送激活码 /// </summary> /// <param name="address"& ...
- 1、IO概述及File类
- c#如何使用replace函数将"\"替换成"\\"
当我使用 String str="c:\aa.xls"; str=str.Replace("\","\\");时,括号为红色错误的,那么如何 ...
- C++中的数学函数汇总
math.h 数学函数库,一些数学计算的公式的具体实现是放在math.h里,具体有: 1 三角函数 double sin (double); double cos (double); double t ...
- SP CAML工具
直接一直使用CAML做一些简单的SP列表查询,突然想对CAML进一步了解,于是找到两个常用工具,做以记录: 1 Caml Query Builder : 用于编写CAML查询,对初学者可以了解查询语句 ...
- mac重启iterm后不会自动加载.bash_profile
我用的zsh,由于平时设置的环境变量都是在.bash_profile文件中,每次重启iterm后,都需要重启手动加载.bash_profile文件,很麻烦. 设置自动加载.bash_profile的方 ...
- HttpWebRequest 以及WebRequest的使用
1.WebRequest的发送数据以及接收数据 class Program { static void Main(string[] args) { //创建一个实例并发送请求 HttpWebReque ...
- 使用Jenkins进行android项目的自动构建(2)
Maven and POM 1. 什么是Maven? 官方的解释是: http://maven.apache.org/guides/getting-started/index.html#What_is ...
- git push失败the remote end hung up unexpectedly
Git Push是老是失败,提示: fatal: the remote end hung up unexpectedly git did not exit cleanly (exit code 1) ...