用%做的,为什么过不了
查看原帖
用%做的,为什么过不了
1217201
liyunhe楼主2024/6/15 17:45

#1,#9都WA了,dalao们能帮忙看看吗

#include<bits/stdc++.h>
#define int long long
using namespace std;
int h[101],dp[101][101],ans;
signed main()
{
    int N;
    cin>>N;
    for(int i=1;i<=N;i++)cin>>h[i];
    h[0]=h[N];h[N+1]=h[1];
    for(int len=2;len<=N;len++){
        for(int l=1;l<=N;l++){
            int r=l+len-1;
            int t=0;
            for(int k=l;k<r;k++){
                t=max(t,dp[l][k%N]+dp[(k+1)%N][r%N]+h[l]*h[(k+1)%N]*h[(r+1)%N]);
            }
            dp[l][r%N]=t;
        }
    }
    for(int l=1;l<=N;l++){
        int r=l+N-1;
        ans=max(ans,dp[l][r%N]);
    }
    cout<<ans;
    return 0;
}
2024/6/15 17:45
加载中...