#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#define ll long long
#define fi first
#define se second
#define pb push_back
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int nax=5e5+5;
signed main(){
iostream::sync_with_stdio(false);
int n;
cin>>n;
int tab[n];
for (int i = 0; i < n; ++i)
{
cin>>tab[i];
}
int dp[n][n];
memset(dp,0,sizeof dp);
for (int i = 0; i < n; ++i)
{
for (int j = i; j < n; ++j)
{
int cnt=0;
int cur=i;
int a=0;
int b=0;
//cout <<i<<" "<<j<<endl;
for (int k = i-1; k >= 0 ; --k)
{
a+=tab[k];
while(cur<=j&&b<a){
b+=tab[cur++];
}
if(a==b&&k!=0&&cur!=j) cnt++;
//cout <<k<<" "<<a<<" "<<b<<endl;
dp[i][j]=max(dp[i][j],dp[k][i-1]+cnt);
}
}
}
int ans=0;
for (int i = 0; i < n; ++i)
{
//cout <<dp[i][n-1]<<endl;
ans=max(ans,dp[i][n-1]);
}cout <<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
87 ms |
1372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |