标签:
f(i,j)=min{f(i,k)+f(k,j)+a[i]*a[k]*a[j]}(1<=i<=j<=n,i<k<j)
#include<cstdio> #include<algorithm> #include<cstring> using namespace std; int n,a[101],f[101][101]; int main() { // freopen("codevs1966.in","r",stdin); scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%d",&a[i]); memset(f,0x7f,sizeof(f)); for(int i=1;i<=n;++i) f[i][i]=0; for(int i=1;i<n;++i) f[i][i+1]=0; for(int l=1;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[k]*a[i]*a[j]); } printf("%d\n",f[1][n]); return 0; }
标签:
原文地址:http://www.cnblogs.com/autsky-jadek/p/4596750.html