循环比赛日程表(match)
【问题描述】
解析
dfs或分治
分治可以不断递归4个小正方形
左上右下为前一半,左下右上后一半
dfs就很无脑了
代码
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int N=1e5+100;
const int M=1e6+100;
int m,n;
int id[1001][1001];
int jd[1001][1001];
int today[1001];
void print() {for(int i=1; i<=n; i++) {for(int j=1; j<=n; j++) {printf("%d ",id[i][j]);}printf("\n");}
}
void dfs(int I,int J) {if(J>n) {mem(today,0);if(I==n) print();else dfs(I+1,1);return;}if(!id[I][J]) {for(int i=1; i<=n; i++) {if(today[i]||jd[J][i]||jd[i][J]) continue;jd[J][i]=jd[i][J]=1;today[i]=today[J]=1;id[I][J]=i;id[I][i]=J;//printf("time:%d a=%d b=%d\n",I,J,i);break;}}dfs(I,J+1);
}
int main() {scanf("%d",&n);n=pow(2,n);dfs(1,1);return 0;
}
/*
1:_ 2:o 3:*
2 10 9
*/