This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 5000;
int d[MAX_N + 1], sd[MAX_N + 1], dp[MAX_N + 1][MAX_N + 1];
int main() {
int n;
cin >> n;
for ( int i = 1; i <= n; i++ ) {
cin >> d[i];
sd[i] = sd[i - 1] + d[i];
}
for ( int i = 1; i <= n; i++ ) {
int k = i, c = 0;
for ( int j = i + 1; j <= n; j++ ) {
while ( k > 0 && sd[i] - sd[k] < sd[j] - sd[i] )
k--;
//printf( "%d %d %d %d\n", k, i, j, sd[j] - sd[i] );
if ( sd[i] - sd[k] == sd[j] - sd[i] )
c++;
if ( k > 0 )
dp[i][j + 1] = max( dp[i][j + 1], dp[k - 1][i] + c );
}
for ( int j = i; j <= n; j++ )
dp[i][j] = max( dp[i][j], max( dp[i - 1][j], dp[i][j - 1] ) );
}
/*for ( int i = 1; i <= n; i++ ) {
for ( int j = 1; j <= n; j++ )
printf( "%d ", dp[i][j] );
printf( "\n" );
}*/
int ans = 0;
for ( int i = 0; i <= n; i++ )
ans = max( ans, dp[i][n] );
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |