讨论 / 麻烦帮忙找下错误;
liaoyu 2017-01-24 14:22:33
点我顶贴 收藏 删除
#include<iostream>

#include<cstdio>

#include<cstring>

using namespace std;

int a[3000];

int maxx[300][300];

int main()

{ memset(maxx,0,sizeof(maxx));

int n;

cin>>n;

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

cin>>a[i];

for(int i=n-1;i>=1;i--)

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

{

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

if(maxx[i][j]<maxx[i][k]+maxx[k+1][j]+a[i]*a[k+1]*a[j+1])

maxx[i][j]=maxx[i][k]+maxx[k+1][j]+a[i]*a[k+1]*a[j+1];

cout<<i<<" "<<j<<" "<<maxx[i][j]<<endl;

}

cout<<maxx[1][n];

return 0;

}

查看更多回复
提交回复