80pts区间dp求条
查看原帖
80pts区间dp求条
845400
lwj54joy楼主2025/7/28 14:08

WA on #8 #9

/*
 * > CPP Code Snippet <
 * > Powered by Microsoft Visual Studio Code <
 *
 * @Author    FrankWKD (wangkedi01)
 * @Date      2025-07-28
 * @Network   "https://www.luogu.com.cn/problem/P1063"
 * @License   GNU General Public License 3.0
 * @Platform  [Frank]iMac Ubuntu Pro 24.04 LTS
 * @FileName  P1063-[NOIP2006].cpp
 * @FilePath  /media/frank/FrankW/_default/Mine/Working/code-spaces/OI/OJ/Luogu/P1063-[NOIP2006].cpp
 * @Solution  --
 */

// #pragma GCC optimize(3)

#define _for(cc, ba, ab) for (int cc = (ba); cc <= (ab); cc++)
#define for_(cc, ba, ab) for (int cc = (ba); cc >= (ab); cc--)
#include <bits/stdc++.h>
using namespace std;
#define int long long
int dp[310][310], n, a[110];
signed main() {
    // freopen("sample.in","r",stdin);
    // freopen("sample.out","w",stdout);
    // ios::sync_with_stdio(false);
    // cin.tie(0); cout.tie(0);
    cin >> n;
    _for(i, 1, n) cin >> a[i], a[i + n] = a[i];
    _for(len, 2, n +1) _for(i, 1, n * 2 - len) {
        int j = i + len - 1;
        _for(k, i, j - 1) dp[i][j] = max(dp[i][j], dp[i][k] + dp[k + 1][j] + a[i] * a[j + 1] * a[k + 1]);
    }
    int ans = 0;
    _for(i, 1, n) ans = max(ans, dp[i][i + n - 1]);
    cout << ans << endl;

    return 0;
}
2025/7/28 14:08
加载中...