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. Linux系统软件包的管理(4)

    虽然使用源码编译安装可以具有提高速度个性化的定制等优点,但对于 Linux发行商来说,则不容易管理软件包,毕竟不是每个人都会进行源码编译的,如果能够将软件预先在相同的硬体与系统上面编译好在发布的话,不 ...

  2. mysql日期时间函数使用总结

     获取函数 mysql默认的时间格式: yyyy-MM-dd 或者 yyyy-MM-dd HH:mm:ss 1. Date() 返回日期部分, date('2018-02-14 17:03:04') ...

  3. 修改ssh远程默认端口

    修改ssh远程默认端口 Linuxssh端口修改 1. 修改ssh配置文件 [root@distzabbix ~]# vim /etc/ssh/sshd_config 找到第17行附近#Port 22 ...

  4. 传输层两大协议:TCP和UDP

    1. UDP 1.1 发送方式(如何发送) 面向无连接. 无状态服务. 不保证不丢失,不保证按顺序到达. 1.2 发送形式(发送的是什么) 基于数据报. 一个一个的发送,一个一个的接收. 1.3 使用 ...

  5. eslint 配置及规则说明

    中文官方网站 安装 可以全局安装,也可以在项目下面安装. 如下是在项目中安装示例,只需要在 package.json 中添加如下配置,并进行安装: “eslint”: “^4.11.0” 配置 配置方 ...

  6. 11-01 Java 开发工具 eclipse从下载、安装到实际使用的详细教程

     Eclipse和MyEclipse简介 Eclipse是一种可扩展的开放源代码的IDE.起始于1999年4月,由OTI和IBM两家公司的IDE产品开发组组建. 2001年11月,IBM公司捐出价值4 ...

  7. 前端安全 -- XSS攻击

    XSS漏洞是最广泛.作用最关键的web安全漏洞之一.在绝大多数网络攻击中都是把XSS作为漏洞链中的第一环,通过XSS,黑客可以得到的最直接利益就是拿到用户浏览器的cookie,从而变相盗取用户的账号密 ...

  8. How To Scan QRCode For UWP (3)

    这一节主要介绍如何去设置MediaCapture拍照的分辨率. MediaCapture 包含一个 VideoDeviceController对象,凭借它可以控制摄像头的很多设置,其中包括设置拍照的分 ...

  9. C++:复制构造函数

    关于复制构造函数的具体细节:浅层复制和深层复制等可以看下 范磊老师的<零起点学通C++>视频教程和<C++ Primer Plus>一书. 相信看完后,对复制构造函数能基本掌握 ...

  10. CentOS7下搭建FastDfs(V5.11)+Keepalived分布式集群部署

    FastDfs介绍 http://kb.cnblogs.com/page/82280/ 1.准备 系统 CentOS7 最小化安装. #VIP虚拟IP 10.1.6.218 #Keepalived 1 ...