이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<long long> vl;
typedef vector<int> vi;
int n;
vi arr;
int dp[3001][3001]; // maximum number of segments if we are at the ith position and the last segment begun at j
int main(){
cin>>n;
arr.resize(n);
for(int i = 0; i < n; i++)
cin>>arr[i];
ll pref[n];
pref[0] = arr[0];
for(int i = 1; i < n; i++) pref[i] = pref[i-1] + arr[i];
memset(dp, 0, sizeof dp);
dp[0][0] = 1;
for(int i = 1; i < n; i++){
for(int j = i; j >= 0; j--){
for(int k = j - 1; k >= 0; k--){
ll sumL = pref[j-1], sumR = pref[i];
if(j > 0) sumR -= pref[j-1];
if(k > 0) sumL -= pref[k-1];
if(sumR >= sumL)
dp[i][j] = max(dp[i][j], dp[j-1][k] + 1);
// cout<<i<<" "<<j<<" "<<sumR<<endl;
// cout<<j-1<<" "<<k<<" "<<sumL<<endl;
// cout<<"DP: "<<dp[i][j]<<endl;
}
}
}
int ans = 0;
for(int i = 0; i < n; i++){
ans = max(ans, dp[n-1][i]);
}
cout<<ans<<endl;
return 0;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |