首页 > 代码库 > noip2006 能量项链

noip2006 能量项链

做noip水题- -

得练dp

先找找信心

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>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<<ans;    }

 

noip2006 能量项链