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
#include <iostream>
#include <vector>
#include <algorithm>

int policz(std::vector<int> &p) {
    if (p.size() == 1) return 0;
    std::vector<int> poz;
    for (int i = 0 ; i < p.size() ; i++) {
        bool ok = true;
        if (i != 0 && p[i-1] > p[i]) ok = false;
        if (i != p.size() - 1 && p[i+1] > p[i]) ok = false;
        if (ok) {
            poz.push_back(p[i]);
        }
    }
    return 1 + policz(poz);
}

int rozpad(int n, int k) {
    std::vector<int> p;
    for(int i = 0  ; i < n ; i++) {
        p.push_back(i);
    }
    int res = 0;
    do {
        if (k == policz(p)) res++;
    } while(std::next_permutation(p.begin(), p.end()));
    return res;
}

int main() {
    int n, k, p;
    std::cin >> n >> k >> p;
    std::cout << rozpad(n, k);
}