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. 02_python_while循环/格式化输出/逻辑运算

    一. while循环 1.基本形式 while 条件: 循环体 # 判断条件是否为真,如果真,执行代码块.然后再次判断条件是否为真.如果真继续执行代码块...直到条件变成了假.循环退出 ps:死循环 ...

  2. SVM的代码实现-python

    隔了好久木有更新了,因为发现自己numpy的很多操作都忘记了,加上最近有点忙... 接着上次 我们得到的迭代函数为 首先j != yi j = yi import numpy as np def sv ...

  3. Spring Boot中使用@Async实现异步调用

    在Spring Boot中,我们只需要通过使用@Async注解就能简单的将原来的同步函数变为异步函数,为了让@Async注解能够生效,还需要在Spring Boot的主程序中配置@EnableAsyn ...

  4. 不一样的日期、时间转换(moment.js)

    无意中遇到了一种很奇怪的日期格式,从接口中返回的日期是这样的,如 2018-02-06T11:59:22+08:00 .然而这却不是我们想要的,我们要的是这种,YYYY-MM-DD HH:mm:ss. ...

  5. 【bzoj3218】a+b Problem 最小割+主席树

    数据范围:$n≤5000$,$a,l,r≤10^9$,$b,w,p≤2\times 10^5$. 我们考虑一种暴力的最小割做法: 首先令$sum=\sum\limits_{i=1}^{n} b_i+w ...

  6. / | \ # $ ^ & *这些符号怎么读

    供参考: /: slash或forward slash 英 [slæʃ] |: vertical bar或pipe #: number sign或pound sign \: backslash 英 [ ...

  7. @JSONField注解的使用

    FastJson中的注解@JSONField,一般作用在get/set方法上面,常用的使用场景有下面三个: 修改和json字符串的字段映射[name] 格式化数据[format] 过滤掉不需要序列化的 ...

  8. c++中堆、栈、自由存储区和常量存储区(转)

    代码段 --text(code segment/text segment)text段在内存中被映射为只读,但.data和.bss是可写的.text段是程序代码段,在AT91库中是表示程序段的大小,它是 ...

  9. 全网最详细的Windows系统里PLSQL Developer 64bit的下载与安装过程(图文详解)

    不多说,直接上干货! ORACLE是数据库,有客户端和服务器: 其,具体下载,可见http://www.oracle.com/technetwork/database/enterprise-editi ...

  10. SQL 日期相减(间隔)datediff函数

    select datediff(year, 开始日期,结束日期); --两日期间隔年 select datediff(quarter, 开始日期,结束日期); --两日期间隔季 select date ...