#include <bits/stdc++.h>
using namespace std;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int n,a[1001];
void read()
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
}
int dp[1001][3001];
void solve()
{
for(int i=0;i<=n;i++)
{
for(int j=0;j<=2*n;j++)
{
dp[i][j]=-1e9;
}
}
for(int i=1;i<=n;i++)
{
if(a[i]==1)dp[i][i]=1;
}
int ans=0;
dp[0][0]=0;
for(int i=1;i<=n;i++)
{
for(int j=i;j<=2*i;j++)
{
for(int pr=1;pr<i;pr++)
{
if(a[pr]!=1)continue;
for(int d=1;d<=n;d++)
{
if(a[d]!=-1)continue;
int f=j-(abs(d-i)+abs(d-pr));
if(f>=0)dp[i][j]=max(dp[i][j],dp[pr][f]+1);
}
}
//cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
ans=max(ans,dp[i][j]);
}
}
cout<<ans<<endl;
}
int main()
{
speed();
read();
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |