标签:== https scanf ima printf read color char cto
题目链接:https://ac.nowcoder.com/acm/contest/3570/H
#include <iostream> #include <algorithm> #include <string> #include <string.h> #include <vector> #include <map> #include <stack> #include <set> #include <queue> #include <time.h> #define LL long long #define INF 0x3f3f3f3f #define ls nod<<1 #define rs (nod<<1)+1 const int maxn = 1e5 + 10; const LL MOD = 1e9 + 7; template<class T>inline void read(T &res) { char c;T flag=1; while((c=getchar())<‘0‘||c>‘9‘)if(c==‘-‘)flag=-1;res=c-‘0‘; while((c=getchar())>=‘0‘&&c<=‘9‘)res=res*10+c-‘0‘;res*=flag; } int ans[20],vis[20],a[20]; int n,cnt; void dfs(int k) { if (k == n+1) { if (abs(a[1]-a[n]) != 1) cnt++; return ; } for (int i = 1;i <= n;i++) { if (!vis[i] && (abs(i-a[k-1]) != 1 || k == 1)) { a[k] = i; vis[i] = 1; dfs(k+1); a[k] = 0; vis[i] = 0; } } } int main() { for (n = 1;n <= 11;n++) { memset(a,0, sizeof(a)); memset(vis,0, sizeof(vis)); cnt = 0; dfs(1); ans[n] = cnt / n / 2; } ans[1] = 1; int t; scanf("%d",&t); while (t--) { scanf("%d",&n); printf("%d\n",ans[n]); } return 0; }
标签:== https scanf ima printf read color char cto
原文地址:https://www.cnblogs.com/-Ackerman/p/12241419.html