0%

[題解]採蘑菇攻略問題

a133. 採蘑菇攻略問題

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define Orz ios::sync_with_stdio(0),cin.tie(0)
#define N 51
#define FOR(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define pid pair<int,double>
#define pdi pair<double,int>
using namespace std;
int n,m;

void solve(){
cin>>n;
int ans = 0,dp[N][N];
memset(dp,0,sizeof(dp));

FOR(i,n){
int temp;cin>>temp;
dp[i][i] = temp;
ans = max(ans,temp);
}
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
dp[i][j] = dp[i][j-1]+dp[j][j];
ans = max(ans,dp[i][j]);
}
}
cout<<ans<<endl;
}

signed main(){
Orz;
int t = 1;
while(t--){
solve();
}
}