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


    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("!
    ")
    #define INF 10000
    #define MAX(a,b) a>b?a:b
    #define blank pf("
    ")
    #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
    ",dp[0][n-1]);
        }
        return 0;
    }
  • 相关阅读:
    The "with" keyword in Javascript
    [导入][Software]SourceForge Enterprise Edition
    Font in Google Adsense
    JavaScript, We Hardly new Ya
    [导入][Fun]Total广告歌
    Prototype 1.5.0_rc2
    Ajax Web Part
    jquery数组(创建对象数组)
    jquery数组(拆分)
    jquery数组(排序)
  • 原文地址:https://www.cnblogs.com/qlky/p/5462291.html
Copyright © 2020-2023  润新知