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
#include <bits/stdc++.h>

using namespace std;

bool t[1000];
vector <long long> p,a;
long long n,k,m,l,w;

int main() {
	scanf("%lld %lld %lld",&n,&k,&m);
	for (long long i=1; i<=n; ++i) p.push_back(i);
	do {
		a=p; l=0;
		while (a.size()>1) {
			if (a[a.size()-1]<a[a.size()-2]) {t[a.size()-1]=1;} else {t[a.size()-1]=0;}
			for (long long i=a.size()-2; i>0; --i) {
				if (a[i]<a[i-1]||a[i]<a[i+1]) {t[i]=1;} else {t[i]=0;}
			}
			if (a[0]<a[1]) {t[0]=1;} else {t[0]=0;}
			for (long long i=a.size()-1; i>=0; --i)
				if (t[i]==1) {a.erase(a.begin()+i);}
			++l;
		}
		if (l==k) ++w;
	} while (next_permutation(p.begin(),p.end()));
	printf("%lld\n",w);
	return 0;
}