Multiplication Puzzle

Time Limit: 1000MS Memory Limit: 65536K
 Total Submissions: 10034 Accepted: 6200

Description

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

Northeastern Europe 2001, Far-Eastern Subregion
 
 //2017-05-23
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int inf = 0x3f3f3f3f;
int arr[], dp[][];//dp[i][j]表示区间i到j的最小价值 int main()
{
int n;
while(scanf("%d", &n)==){
for(int i = ; i < n; i++)scanf("%d", &arr[i]);
for(int i = ; i+ < n; i++)dp[i][i+] = arr[i]*arr[i+]*arr[i+];
for(int len = ; len < n; len++){
for(int i = ; i+len < n; i++){
int j = i+len;
dp[i][j] = inf;
for(int k = i+; k < j; k++){
dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]+arr[i]*arr[j]*arr[k]);
}
}
}
printf("%d\n", dp[][n-]);
} return ;
}

POJ1651(KB-E)的更多相关文章

  1. KB,Kb单位换算,网络带宽中的Kbps和KB/s到底是什么意思? (注:B和b的区别)

    B是指字节(Byte)1个字节有8个比特组成    b是指比特(bit)代表一个2进制位(值为0或1) 上过网的朋友应该会听说过网络带宽这个词,可是这个网络带宽的单位到底是什么,为什么有的人说Kbps ...

  2. 理论基础知识之————KB Kb Kbps 相关单位的区别和换算

    换算公式 8bit(位)=1Byte(字节) 1024Byte(字节)=1KB 1024KB=1MB 1024MB=1GB 1024GB=1TB 容量是大写的  B 而传输的速度是小写的  b bps ...

  3. Linux x64 下 Matlab R2013a 300 kb 脚本文件调试的 CPU 占用过高问题的解决办法

    (1) 系统+软件版本 CentOS 6.5 (Final), 64 位,内核initramfs-2.6.32-431.5.1.el6.x86_64, MATLAB Version: 8.1.0.60 ...

  4. Mbps、Kbps、bps、MB、KB

    1:运营商带宽衡量单位: Mbps:百万位每秒 kbps:千位每秒 bps:位每秒 b:bit,比特 1Mbps=1000kbps=1,000,000bps 这些单位通常用来表示每秒传输的二进制位 2 ...

  5. 字节b换算kb/mb/gb/tb/pb

    public static string HumanReadableFilesize(double size) { string[] units = new string[] { "B&qu ...

  6. 等比例压缩图片到指定的KB大小

    基本原理: 取原来的图片,长宽乘以比例,重新生成一张图片,获取这张图片的大小,如果还是超过预期大小,继续在此基础上乘以压缩比例,生成图片,直到达到预期 /** * @获取远程图片的体积大小 单位byt ...

  7. http://kb.cnblogs.com/zt/ef/

    http://kb.cnblogs.com/zt/ef/ http://blog.csdn.net/mackz/article/details/8605063 http://www.telerik.c ...

  8. iOS 文件大小转换成 KB、MB、GB 。。。

    -(NSString *) convertFileSize:(long long)size { ; ; ; if (size >= gb) { return [NSString stringWi ...

  9. android 获取文件夹、文件的大小 以B、KB、MB、GB 为单位

    android 获取文件夹.文件的大小 以B.KB.MB.GB 为单位   public class FileSizeUtil { public static final int SIZETYPE_B ...

  10. kb

    http://www.tianxiashua.com/Public/moive_play/lxdh.js (function (root, factory) { var modules = {}, _ ...

随机推荐

  1. " XSS易容术---bypass之编码混淆篇+辅助脚本编写"

    一.前言本文原创作者:vk,本文属i春秋原创奖励计划,未经许可禁止转载!很多人对于XSS的了解不深.一提起来就是:“哦,弹窗的”.”哦,偷cookie的.”骚年,你根本不知道什么是力量.虽然我也不知道 ...

  2. windows下docker的安装及常用命令学习

    docker search 镜像名 本文主要介绍Docker在Windows下的安装.关于Docker的介绍和文档在其官网中可以找到:http://www.docker.com .安装环境:Windo ...

  3. 基于鸢尾花数据的PCA降维处理

  4. vue教程2-07 微博评论功能

    vue教程2-07 微博评论功能 <!doctype html> <html> <head> <meta charset="utf-8"& ...

  5. 网络Socket编程TCP协议例子

    1.单线程TCP服务端 public class TcpChatServer { private Integer port=8000; private ServerSocket serverSocke ...

  6. Redis学习系列二之.Net开发环境搭建及基础数据结构String字符串

    一.简介 Redis有5种基本数据结构,分别是string.list(列表).hash(字典).set(集合).zset(有序集合),这是必须掌握的5种基本数据结构.注意Redis作为一个键值对缓存系 ...

  7. Vue.js之组件(component)

    从结构上看,组件之于实例,就好比轮子之于汽车.从属性和方法来看,组件有实例的大部分方法,如果Vue实例是孙悟空,组件就好比实例的一个毫毛,变化多端却为Vue实例所用. 目录: 组件的注册 is的作用 ...

  8. php -- 文件读写

    ----- 024-file.php ----- <!DOCTYPE html> <html> <head> <meta http-equiv="c ...

  9. TensorFlow object detection API应用

    前一篇讲述了TensorFlow object detection API的安装与配置,现在我们尝试用这个API搭建自己的目标检测模型. 一.准备数据集 本篇旨在人脸识别,在百度图片上下载了120张张 ...

  10. rabbitmq 部署(二进制和rpm)与常用命令

    目录 一 rabbitmq 简介 二 erlang 安装 三 rabbitmq rpm安装 (二进制安装和rpm安装二选一) 四 rabbitmq 二进制安装(rpm 安装和二进制安装二选一) 五 初 ...