POJ1651 Multiplication Puzzle | 区间DP

题目:

http://poj.org/problem?id=1651


题解:

不知道为什么

想了想就会做了

写得还很短

题大概是水吧

解出来也不费劲

#include<cstdio>
#include<algorithm>
#include<cstring>
#define N 105
using namespace std;
int n,a[N],f[N][N];
int main()
{
    scanf("%d",&n);
    memset(f,127/3,sizeof(f));
    for (int i=1;i<=n;i++) f[i][i+1]=0,scanf("%d",a+i);
    for (int l=2;l<=n;l++)
    for (int i=1;i<=n;i++)
    {
        int j=i+l;if (j>n) break;
        for (int k=i+1;k<j;k++)
        f[i][j]=min(f[i][j],f[i][k]+f[k][j]+a[i]*a[j]*a[k]);
    }
    printf("%d\n",f[1][n]);
    return 0;
}

 

posted @ 2018-01-08 16:31  MSPqwq  阅读(122)  评论(0编辑  收藏  举报