Alguns problemas de PD em range um dia antes da OBI
This commit is contained in:
37
Problems/USACO/usaco2016_3.cpp
Normal file
37
Problems/USACO/usaco2016_3.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define USACOIN ifstream cin("248.in"); ofstream cout("248.out");
|
||||
|
||||
using namespace std;
|
||||
vector<vector<int>> dp;
|
||||
vector<int>v;
|
||||
|
||||
int main(){
|
||||
USACOIN
|
||||
ios::sync_with_stdio(false);
|
||||
|
||||
int n, answ = 0;
|
||||
cin >> n;
|
||||
|
||||
v.resize(n);
|
||||
dp.assign(n, vector<int>(n, 0));
|
||||
for(int i = 0; i < n; i++){
|
||||
cin >> v[i];
|
||||
dp[i][i] = v[i];
|
||||
answ = max(answ, v[i]);
|
||||
}
|
||||
|
||||
for(int j = 1; j < n; j++){
|
||||
for(int i = j-1; i >= 0; i--){ // Creating answer for interval i-j
|
||||
for(int k = i; k < j; k++){ // Checking if best answer is merging i-k with k+1-j
|
||||
if(dp[i][k] != 0 && dp[k+1][j] != 0 && dp[i][k] == dp[k+1][j]){
|
||||
dp[i][j] = dp[i][k]+1;
|
||||
answ = max(answ, dp[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << answ << '\n';
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user