#include<bits/stdc++.h> using namespace std; #define PB push_back #define ST first #define ND second int checkv(vector<int> v) { if(v.size() == 1) return 0; vector<int> g; for(int i=0; i < v.size(); i++) { bool ch = true; if(i > 0 && v[i-1] > v[i]) ch = false; if(i+1 < v.size() && v[i] < v[i+1]) ch = false; if(ch) g.PB(v[i]); } return checkv(g)+1; } int ile[20]; int main() { int n, k, p; ios_base::sync_with_stdio(0); cin >> n >> k >> p; if(k > 12) { cout << "0\n"; return 0; } vector<int> v; for(int i=1; i <= n; i++) v.PB(i); map<int, int> mapa; do { int res=checkv(v); ile[res]++; }while(next_permutation(v.begin(), v.end())); cout << ile[k] << "\n"; }
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include<bits/stdc++.h> using namespace std; #define PB push_back #define ST first #define ND second int checkv(vector<int> v) { if(v.size() == 1) return 0; vector<int> g; for(int i=0; i < v.size(); i++) { bool ch = true; if(i > 0 && v[i-1] > v[i]) ch = false; if(i+1 < v.size() && v[i] < v[i+1]) ch = false; if(ch) g.PB(v[i]); } return checkv(g)+1; } int ile[20]; int main() { int n, k, p; ios_base::sync_with_stdio(0); cin >> n >> k >> p; if(k > 12) { cout << "0\n"; return 0; } vector<int> v; for(int i=1; i <= n; i++) v.PB(i); map<int, int> mapa; do { int res=checkv(v); ile[res]++; }while(next_permutation(v.begin(), v.end())); cout << ile[k] << "\n"; } |