제출 #1278493

#제출 시각아이디문제언어결과실행 시간메모리
1278493hoangtien69Cigle (COI21_cigle)C++20
100 / 100
204 ms134548 KiB
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 5005;

int n;
int a[MAXN];
int pf[MAXN][MAXN];
int dp[MAXN][MAXN];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    for (int i = 2; i <= n; i++)
    {
        int trai = i - 1;
        int peal1 = 0;
        int peal2 = 0;
        int dem = 0;
        for (int j = i; j <= n; j++)
        {
            dp[i][j] = max(dp[i][j - 1], pf[i - 1][trai] + dem);
            peal1 += a[j];
            while (trai > 1 and peal1 > peal2)
            {
                peal2 += a[trai];
                trai--;
            }
            if (peal2 == peal1)
            {
                dem++;
            }
        }
        for (int k = 1; k <= i; k++)
        {
            pf[i][k] = max(pf[i][k - 1], dp[k][i]);
        }
    }
    int res = 0;
    for (int i = 1; i <= n; i++)
    {
        res = max(res, dp[i][n]);
    }
    cout << res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...