#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 2500 + 2;
const int M = 2e5 + 2;
const int inf = 1e9;
int n, p, is[16], ans;
vector<int> v;
void Gener(int i, int j) {
if (j == n) {
vector<int> b;
for (int i = 0; i < 2 * n; i++) if (is[i] == 0) b.push_back(i);
do {
int moze = 1;
for (int i = 0; i < n; i++) moze &= v[i] < b[i];
if (moze == 0) continue;
int alg1, alg2;
alg1 = alg2 = 0;
int mx = -1;
for (int i = 0; i < n; i++) {
if (mx < v[i]) {
alg1 += 1;
mx = b[i];
}
}
vector<int> dp(n);
for (int i = n - 1; i >= 0; i--) {
dp[i] = 1;
for (int j = i + 1; j < n; j++) {
if (b[i] < v[j]) smax(dp[i], dp[j] + 1);
}
smax(alg2, dp[i]);
if (alg1 < alg2) break;
}
if (alg1 < alg2) ans += 1;
if (ans == p) ans = 0;
} while (next_permutation(b.begin(), b.end()));
return;
}
if (i == 2 * n) return;
v.push_back(i);
is[i] = 1;
Gener(i + 1, j + 1);
is[i] = 0;
v.pop_back();
Gener(i + 1, j);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> p;
Gener(0, 0);
cout << ans << en;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |