做noip水题- -
得练dp
先找找信心
#include#include #include #include using namespace std;int a[1000];int f[1000][1000];int main(){ int n; cin>>n; for (int i=1;i<=n;i++) { cin>>a[i]; a[i+n]=a[i]; } for (int l=2;l<=n;l++) for (int i=1;i<=2*n;i++) for (int j=i+1;j<=i+l-1;j++) f[i][i+l-1]=max(f[i][i+l-1],a[j]*a[i]*a[i+l]+f[i][j-1]+f[j][i+l-1]); int ans=0; for (int i=1;i<=n;i++) ans=max(ans,f[i][i+n-1]); cout<