http://poj.org/problem?id=1651Multiplication Puzzle
 
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6188   Accepted: 3777

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
题意:

从中间选择一个数乘以左右俩边的数,第一个和最后一个不能选择,这个数就拿出来,怎样拿出来的顺序,使总和最小。

分析:abc sum=a*b*c;

abcd sum1=abc+acd;

sum2=bcd+abd;

sum=min(sum1,sum2)

dp[i][j]=min(dp[i][j],a[i]*a[g]*a[j]+dp[i][g]+dp[g][j]);(i<g<j)

也就是说igj,向该数列插入数字,是i和g之间或者是g和i之间。
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int dp[][];
int main()
{
int i,j,k,n,a[],g;
while(~scanf("%d",&n))
{
memset(dp,,sizeof(dp));
for(i=;i<n;i++)
scanf("%d",&a[i]);
for(k=;k<n;k++)//保证最小有3位数。
{
for(i=;i<n-k;i++)
{
j=i+k;
dp[i][j]=;//求最小,初始化最大。
for(g=i+;g<j;g++)
dp[i][j]=min(dp[i][j],a[i]*a[g]*a[j]+dp[i][g]+dp[g][j]);
}
} printf("%d\n",dp[][n-]);
}
return ;
}
/*
6
10 1 50 50 20 5
3650
*/
												

poj 1651 http://poj.org/problem?id=1651的更多相关文章

  1. poj-3056 http://poj.org/problem?id=3056

    http://poj.org/problem?id=3056 The Bavarian Beer Party Time Limit: 6000MS   Memory Limit: 65536K Tot ...

  2. poj 1679 http://poj.org/problem?id=1679

    http://poj.org/problem?id=1679 The Unique MST Time Limit: 1000MS   Memory Limit: 10000K Total Submis ...

  3. POJ3278http://poj.org/problem?id=3278

    http://poj.org/problem?id=3278 题目大意: m,n两个数m可+1, -1, *2变成n,需要经过几步 #include<stdio.h> #include&l ...

  4. OpenJudge/Poj 1207 The 3n + 1 problem

    1.链接地址: http://bailian.openjudge.cn/practice/1207/ http://poj.org/problem?id=1207 2.题目: 总时间限制: 1000m ...

  5. POJ 3320 Jessica‘s Reading Problem(哈希、尺取法)

    http://poj.org/problem?id=3320 题意:给出一串数字,要求包含所有数字的最短长度. 思路: 哈希一直不是很会用,这道题也是参考了别人的代码,想了很久. #include&l ...

  6. poj 1681 Painter&#39;s Problem(高斯消元)

    id=1681">http://poj.org/problem? id=1681 求最少经过的步数使得输入的矩阵全变为y. 思路:高斯消元求出自由变元.然后枚举自由变元,求出最优值. ...

  7. POJ 3100 Root of the Problem || 1004 Financial Management 洪水!!!

    水两发去建模,晚饭吃跟没吃似的,吃完没感觉啊. ---------------------------分割线"水过....."--------------------------- ...

  8. <挑战程序设计竞赛> poj 3320 Jessica's Reading Problem 双指针

    地址 http://poj.org/problem?id=3320 解答 使用双指针 在指针范围内是否达到要求 若不足要求则从右进行拓展  若满足要求则从左缩减区域 代码如下  正确性调整了几次 然后 ...

  9. 尺取法 POJ 3320 Jessica's Reading Problem

    题目传送门 /* 尺取法:先求出不同知识点的总个数tot,然后以获得知识点的个数作为界限, 更新最小值 */ #include <cstdio> #include <cmath> ...

随机推荐

  1. REST_FRAMEWORK加深记忆-加了用户登陆认证,自定义权限的API接口

    哈哈,终于快结束了.. urls.py from django.conf.urls import include, url from django.contrib import admin urlpa ...

  2. hdu 4038 Stone

    思路: 如果负数的个数为偶数则不必改变,为奇数就将最大负数变为正: 对于正数,尽量将1,2变为3即可. 代码如下: #include<cstring> #include<iostre ...

  3. Android:控件的隐藏显示

    布局中的:android:visibility 程序中可用setVisibility(); 对应的三个常量值:0.4.8 VISIBLE:0 意思是可见的INVISIBILITY:4 意思是不可见的, ...

  4. c 语言练习__求到N的阶乘的和。

    #include <stdio.h> /* 题目如下 * S = 1 + 2! + 3! + ... + N! */ int main(int argc, char *argv[]) { ...

  5. 在Ubuntu下安装imx6linux系统的交叉编译环境遇到的问题总结

    这段时间一直忙于手上的嵌入式项目,可以说自己从嵌入式的菜鸟一点点的入门了,关于嵌入式和imx6核心板的开发有了一点的了解,尤其是对于板子环境的搭建.硬件的开发,搭建环境,是一个很大的工程量,也是很重要 ...

  6. HDFS小文件处理——Mapper处理

    处理小文件的时候,可以通过org.apache.hadoop.io.SequenceFile.Writer类将所有文件写出到一个seq文件中. 大致流程如下: 实现代码: package study. ...

  7. NDK(18)使用C++ STL

    1,在Application.mk 中使用 APP_STL := stlport_static 等. APP_ABI := x86 armeabi APP_PLATFORM := android-15 ...

  8. [Codeforces673B]Problems for Round(思路,规律)

    题目链接:http://codeforces.com/contest/673/problem/B 现在有n个题和m个相似的关系,现在要把他们分到2组去. 要求: 1组的所有题比2组难 每个组都得至少有 ...

  9. fil_space_t

    typedef struct fil_space_struct fil_space_t; /** Tablespace or log data space: let us call them by a ...

  10. 给你的JAVA程序配置参数(Properties的使用)

    我们在写JAVA程序时,很多时候运行程序的参数是需要动态改变的 测试时一系列参数,运行时一系列参数 又或者数据库地址也需要配一套参数,以方便今后的动态部署 这些变量的初始化,我们在写小DEMO时完全可 ...