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"holiday.h"
#include <bits/stdc++.h>
using namespace std;
const int N=3055;
long long dp[N][N*3];
bool vis[N];
int a[N];
int n;
long long bt(int i , int d)
{
if(d==0)
return 0;
// if(dp[i][d]!=-1)
// return dp[i][d];
if(d==1)
{
if(!vis[i])
dp[i][d]=a[i];
else
dp[i][d]=0;
return dp[i][d];
}
long long ret=0;
if(i+1<n)
ret=max(bt(i+1,d-1),ret);
if(i)
ret=max(bt(i-1,d-1),ret);
if(i+1<n&&!vis[i])
{
vis[i]=1;
ret=max(bt(i+1,d-2)+a[i],ret);
vis[i]=0;
}
if(i&&!vis[i])
{
vis[i]=1;
ret=max(bt(i-1,d-2)+a[i],ret);
vis[i]=0;
}
dp[i][d]=ret;
return ret;
}
long long int findMaxAttraction(int m, int start, int d, int ar[])
{
memset(dp,-1,sizeof dp);
n=m;
for(int i=0;i<n;i++)
a[i]=ar[i];
return bt(start,d);
}
Compilation message (stderr)
grader.cpp: In function 'int main()':
grader.cpp:7:12: warning: variable 'n_s' set but not used [-Wunused-but-set-variable]
int i, n_s;
^~~
# | 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... |