#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
ifstream f("teroristi2.in");
ofstream g("teroristi2.out");
int N;
int h[5005];
int dp[5005][5005];
int main ()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>N;
for(int i=1;i<=N;i++)
{
cin>>h[i];
}
for(int fin=1;fin<=N;fin++)
{
for(int start=fin;start>=1;start--)
{
vector<int> sp(N+5,0);
for(int j=fin;j>=start;j--)
{
sp[j]=sp[j+1]+h[j];
}
int sum=0,layers=0,cnt=fin;
for(int fin2=fin+1;fin2<=N;fin2++)
{
///dp[fin+1][fin2]=max(dp[fin+1][fin2],dp[start][fin]+layers)
sum+=h[fin2];
while(sum>sp[cnt]&&cnt>start)
{
cnt--;
}
if(sum==sp[cnt]&&cnt!=start)
{
layers++;
}
dp[fin+1][fin2]=max(dp[fin+1][fin2],dp[start][fin]+layers);
}
}
}
int rez=0;
for(int i=1;i<=N;i++)
{
rez=max(rez,dp[i][N]);
// cout<<i<<" "<<dp[i][N]<<'\n';
}
cout<<rez<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
109 ms |
2732 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |