#include #include using namespace std; const int MAX_N = 20; const int BUF = 1 << MAX_N; int N, K; void read() { cin >> N >> K; --K; } int rec(bool decreased, int k, int mask, int dp[2][MAX_N][BUF]) { if (mask == (1 << N) - 1) { return decreased ? 1 : 0; } int &ret = dp[decreased][k][mask]; if (ret != -1) return ret; ret = 0; for (int i = 0; i < N; ++i) { if (mask & (1 << i)) { continue; } if (decreased && i < k) { continue; } ret += rec(decreased | (i < k), i, mask | (1 << i), dp); } return ret; } void work() { static int dp[2][MAX_N][BUF]; memset(dp, -1, sizeof(dp)); cout << rec(0, K, 1 << K, dp) << endl; } int main() { read(); work(); return 0; }