이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
#define ll long long
#define F first
#define S second
#define pll pair<ll , ll>
#define pii pair<int, int>
#define pb push_back
using namespace std;
const int N = 402, inf = (int)1e9 + 7;
int n, d, a[N];
int dp[N][N];
vector<int> vct;
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> d;
for(int i = 1; i <= n; i ++) cin >> a[i], vct.pb(a[i]);
sort(vct.begin(), vct.end()); unique( vct.begin(), vct.end());
for(int i = 1; i <= n; i ++){
a[i] = (lower_bound(vct.begin(), vct.end(), a[i]) - vct.begin());
// cout << a[i] << " ";//endl;
}//cout << endl;
for(int i = 0; i <= n; i ++)fill(dp[i], dp[i] + N, -inf);
dp[1][a[1]] = 1;
for(int i = 2; i <= n; i ++){
dp[i][a[i]] = 1;
for(int k = 0 ; k < a[i]; k ++)
for(int j = max(1, i-d); j < i; j ++)dp[i][a[i]] = max(dp[i][a[i]] , dp[j][k] + 1);
for(int k = a[i]; k <= n; k ++)
for(int j = max(1 ,i-d); j < i; j ++)dp[i][k] = max(dp[i][k], dp[j][k]);
// for(int j = 0 ; j <= n; j ++)cout << i << " " << j << " : " <<max(0, dp[i][j]) << endl;
}
int ret = 0;
for(int i = 0; i <= n; i ++)ret = max(ret, dp[n][i]);
cout << ret << endl;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |