标签:nbsp none 集中 范围 while 输入 子集 else namespace
#include <cstdio> bool ab[40][40],ac[40][40],bd[40][40],cd[40][40]; int e[1200000]; int i,j,n; long long s; inline void dfs(int x,int bb,int cc,int dd) { if (x==n+1) s++; else { for (int b=bb;b!=0;b=b-(b&(-b))) { int i=e[b&(-b)]; if (ab[x][i]) for (int c=cc;c!=0;c=c-(c&(-c))) { int j=e[c&(-c)]; if (ac[x][j]) for (int d=dd;d!=0;d=d-(d&(-d))) { int k=e[d&(-d)]; if ((bd[i][k]) && (cd[j][k])) dfs(x+1,bb^(1<<(i-1)),cc^(1<<(j-1)),dd^(1<<(k-1))); } } } } return; } int main() { scanf("%d",&n); for (i=1;i<=n;i++) for (j=1;j<=n;j++) ab[i][j]=ac[i][n+i-j]=bd[j][i+j-1]=cd[n+i-j][i+j-1]=true; for (i=1,j=1;j<=2*n;i=i<<1,j++) e[i]=j; dfs(1,(1<<n)-1,(1<<(2*n-1))-1,(1<<(2*n-1))-1); printf("%d\n%lld\n",n,s); return 0; }
#include <bits/stdc++.h> using namespace std; typedef int ll; inline ll read() { ll s=0; bool f=0; char ch=‘ ‘; while(!isdigit(ch)) {f|=(ch==‘-‘); ch=getchar();} while(isdigit(ch)) {s=(s<<3)+(s<<1)+(ch^48); ch=getchar();} return (f)?(-s):(s); } #define R(x) x=read() inline void write(ll x) { if(x<0) {putchar(‘-‘); x=-x;} if(x<10) {putchar(x+‘0‘); return;} write(x/10); putchar((x%10)+‘0‘); } #define W(x) write(x),putchar(‘ ‘) #define Wl(x) write(x),putchar(‘\n‘) int n; int main() { freopen("quadripartite.in","r",stdin); freopen("quadripartite.out","w",stdout); R(n); Wl(n); if(n==3) puts("78"); else if(n==4) puts("4196"); else if(n==5) puts("456920"); else if(n==6) puts("88142144"); else puts("27913176688"); return 0; }
标签:nbsp none 集中 范围 while 输入 子集 else namespace
原文地址:https://www.cnblogs.com/gaojunonly1/p/11252753.html