码迷,mamicode.com
首页 > 其他好文 > 详细

POJ1651 Multiplication Puzzle(相邻乘积之和最小,区间DP)

时间:2016-05-05 17:35:12      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:

http://blog.csdn.net/libin56842/article/details/9747021

http://www.cnblogs.com/devil-91/archive/2012/06/26/2562976.html

#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <cctype>
#include <vector>
#include <iterator>
#include <set>
#include <map>
#include <sstream>
using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define pf printf
#define sf scanf
#define spf sprintf
#define pb push_back
#define debug printf("!\n")
#define INF 10000
#define MAX(a,b) a>b?a:b
#define blank pf("\n")
#define LL long long
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define pqueue priority_queue

const int MAXN = 1000 + 5;

int n,m;

int dp[110][110];
int a[110];

int main()
{
    int i,j;
    while(sf("%d",&n)==1)
    {
        mem(dp,0);
        for(i =0;i<n;i++)
            sf("%d",&a[i]);
        for(int l = 2;l<n;l++)
        {
            for(i=0;i<n-l;i++)
            {
                j = i+l;
                dp[i][j] = 1<<30;
                for(int k =i+1;k<j;k++)
                {
                    dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j]+a[k]*a[i]*a[j]);
                }
            }
        }
        pf("%d\n",dp[0][n-1]);
    }
    return 0;
}

 

POJ1651 Multiplication Puzzle(相邻乘积之和最小,区间DP)

标签:

原文地址:http://www.cnblogs.com/qlky/p/5462291.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!