#include<bits/stdc++.h>
using namespace std;
#define lli long long
#define INF LONG_LONG_MAX
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define endl '\n'
#define max(aa, bb) (aa > bb ? aa:bb)
#define min(aa, bb) (aa < bb ? aa:bb)
#define all(aa) aa.begin(), aa.end()
int main(){
#ifdef ONLINE_JUDGE
freopen("zgir.gir", "r", stdin);
freopen("zcik.cik", "w", stdout);
#endif
lli n;
cin>>n;
vector<lli> v(n);
for(auto &it:v) cin>>it;
lli dp[2006][1006];
memset(dp, -1, sizeof(dp));
function<lli(lli, lli)> f= [&] (lli i, lli r) -> lli{
if(r<=0) return 0;
if(i>=n) return -INF;
if(dp[i][r]!=-1) return dp[i][r];
return dp[i][r]=max(f(i+2, r-1)+v[i], f(i+1, r));
};
for(lli j=1;j<=(n+1)/2;j++){
cout<<f(0, j)<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
104 ms |
16512 KB |
Output is correct |
2 |
Correct |
106 ms |
16504 KB |
Output is correct |
3 |
Correct |
102 ms |
16504 KB |
Output is correct |
4 |
Correct |
102 ms |
16504 KB |
Output is correct |
5 |
Correct |
99 ms |
16512 KB |
Output is correct |
6 |
Correct |
99 ms |
16632 KB |
Output is correct |
7 |
Correct |
107 ms |
16504 KB |
Output is correct |
8 |
Correct |
109 ms |
16632 KB |
Output is correct |
9 |
Correct |
103 ms |
16508 KB |
Output is correct |
10 |
Correct |
104 ms |
16512 KB |
Output is correct |
11 |
Correct |
100 ms |
16536 KB |
Output is correct |
12 |
Correct |
101 ms |
16512 KB |
Output is correct |
13 |
Correct |
105 ms |
16532 KB |
Output is correct |
14 |
Correct |
97 ms |
16512 KB |
Output is correct |
15 |
Correct |
98 ms |
16504 KB |
Output is correct |
16 |
Correct |
97 ms |
16504 KB |
Output is correct |
17 |
Correct |
101 ms |
16512 KB |
Output is correct |
18 |
Correct |
100 ms |
16504 KB |
Output is correct |
19 |
Correct |
102 ms |
16660 KB |
Output is correct |
20 |
Correct |
99 ms |
16504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
104 ms |
16512 KB |
Output is correct |
2 |
Correct |
106 ms |
16504 KB |
Output is correct |
3 |
Correct |
102 ms |
16504 KB |
Output is correct |
4 |
Correct |
102 ms |
16504 KB |
Output is correct |
5 |
Correct |
99 ms |
16512 KB |
Output is correct |
6 |
Correct |
99 ms |
16632 KB |
Output is correct |
7 |
Correct |
107 ms |
16504 KB |
Output is correct |
8 |
Correct |
109 ms |
16632 KB |
Output is correct |
9 |
Correct |
103 ms |
16508 KB |
Output is correct |
10 |
Correct |
104 ms |
16512 KB |
Output is correct |
11 |
Correct |
100 ms |
16536 KB |
Output is correct |
12 |
Correct |
101 ms |
16512 KB |
Output is correct |
13 |
Correct |
105 ms |
16532 KB |
Output is correct |
14 |
Correct |
97 ms |
16512 KB |
Output is correct |
15 |
Correct |
98 ms |
16504 KB |
Output is correct |
16 |
Correct |
97 ms |
16504 KB |
Output is correct |
17 |
Correct |
101 ms |
16512 KB |
Output is correct |
18 |
Correct |
100 ms |
16504 KB |
Output is correct |
19 |
Correct |
102 ms |
16660 KB |
Output is correct |
20 |
Correct |
99 ms |
16504 KB |
Output is correct |
21 |
Runtime error |
200 ms |
38136 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |