poj1651

dp

View Code
#include <iostream>

#include <cstdlib>

#include <cstdio>

#include <cstring>

using namespace std;



#define maxn 105

#define inf 0x3f3f3f3f



int n;

int f[maxn];

int g[maxn][maxn];



int main()

{

    //freopen("t.txt", "r", stdin);

    scanf("%d", &n);

    for (int i = 0; i < n; i++)

        scanf("%d", &f[i]);

    memset(g, 0, sizeof(g));

    for (int i = 2; i < n; i++)

        for (int j = 0; j + i < n; j++)

        {

            g[j][j + i] = inf;

            for (int k = j + 1; k < j + i; k++)

                g[j][j + i] = min(g[j][j + i], g[j][k] + g[k][j + i] + f[k] * f[j] * f[j + i]);

        }

    printf("%d\n", g[0][n - 1]);

    return 0;

}

 

你可能感兴趣的:(poj)