提交时间:2021-04-03 11:06:08
运行 ID: 6527
/*#include <bits/stdc++.h> #define int long long using namespace std; int n, M; int a[200], ans = 0; bool vis[200]; void dfs(int num, int lst) { if(num == n + 1) { ans++; return; } for(int i = 1; i <= n; i++) { if(vis[i] || abs(lst - i) == 1) continue; vis[i] = true; a[num] = i; dfs(num + 1, i); vis[i] = false; } } signed main() { for(n = 1; n <= 15; n++) { ans = 0; dfs(1, -1); cout << ans << ", "; } return 0; } */ #include <iostream> //#include <bits/stdc++.h> #define int long long using namespace std; int ans[20] = {0, 1, 0, 0, 2, 14, 90, 646, 5242, 47622, 479306, 5296790, 63779034, 831283558, 11661506218, 175203184374}; int n, M; int dp[1008][1008][2]; signed main() { while(cin >> n >> M) { if(n <= 15) { cout << ans[n] % M << endl; continue; } } return 0; }