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 ...
随机推荐
- SQL SELECT DISTINCT 语句 用法
SQL SELECT DISTINCT 语句 在表中,可能会包含重复值.这并不成问题,不过,有时您也许希望仅仅列出不同(distinct)的值. 关键词 DISTINCT 用于返回唯一不同的值. 语法 ...
- E. Dasha and Puzzle 数学题
http://codeforces.com/contest/761/problem/E 给出一颗树,要求在坐标系中用平行于坐标轴的线描绘出来. 要求边不能相交,而且点的坐标唯一. 注意到2^1 + 2 ...
- 微信里去掉下拉select的边框
<select name="gender" id="" class=" " style=" -webkit-appeara ...
- 可变类型的安全性——更锋利的C#代码小记(2)
ReadOnlyCollection类型是.NET系统类库提供的一个只读集合类型,它与原来的List<string>不存在任何类型转换关系,因此可以从根本上阻止外部对其的修改操作using ...
- 面相切面编程AOP以及在Unity中的实现
一.AOP概念 AOP(Aspect-Oriented Programming,面向切面的编程),它是可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术.它是 ...
- JAVA高级特性反射和注解
反射: 枚举反射泛型注解.html34.3 KB 反射, 主要是指通过类加载, 动态的访问, 检测和修改类本身状态或行为的一种能力, 并能根据自身行为的状态和结果, 调整或修改应用所描述行为的状态和相 ...
- 完美单例宏定义(兼容ARC和MRC),项目中可以直接使用
单例模式: 1.永远只分配一块内存来创建对象 2.提供一个类方法, 返回内部唯一的一个对象(一个实例) 3.最好保证init方法也只初始化一次 写一个宏定义文件,传入宏定义函数名,自动生成符合类名的 ...
- 简单工厂模式-Java篇
简单工厂模式就是考虑如何实例化对象的问题,就是说到底要实例化谁,将来会不会增加实例化对象,比如计算器类中增加开根元素,应该考虑用一个单独的类来创造实例的过程,这就是工厂.下面将利用计算器类举例,解释简 ...
- GIS在石油行业中的应用
在石油工业中,发现新的石油资源,取得竞争优势,是成功的关键之一.GIS系统能帮助评估潜在的石油资源,及时.准确.直观地定位油气资源的空间分布及其特征,以正确有效地开展部署勘探开发工作,占领市场先机. ...
- RDO、SAD、SATD、λ相关概念【转】
率失真优化概述: 率失真优化(Rate D isto r t i on Op t i m ized)策略是在率失真理论[3 ]的基础上提出的一种代价函数方案, RDO 的主要思想是, 在计算代价函数时 ...