Bzoj1501: [NOI2005]智慧珠游戏

题面

Bzoj

我写这篇题解的原因

证明我是一个有耐心的人

Sol

爆搜
先判断有没有小于三的联通块
然后\(AC\)

其实不用像我这样打的
主要是打了一半时发现可以打个表循环找,然而打了一半,所以就只写了\(20k\)(逃
其实也就写了不到一个小时
其实也就调了几分钟
。。。
。。。
。。。
我代码又臭又长被关了起来

# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;

IL int Input(){
    RG int x = 0, z = 1; RG char c = getchar();
    for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
    for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
    return x * z;
}

int vis[50][50], G = 10, use[20];

IL void Out(){
	for(RG int i = 1; i <= 10; ++i, puts(""))
		for(RG int j = 1; j <= i; ++j)
			printf("%c", vis[i + G][j + G] + 'A' - 1);
	exit(0);
}

IL bool Check(RG int x, RG int y, RG int tp, RG int r){
	x += G, y += G;
	if(tp == 1){
		if(use[1]) return 1;
		if(r == 1) return vis[x][y] + vis[x + 1][y] + vis[x][y + 1];
		if(r == 2) return vis[x][y] + vis[x][y + 1] + vis[x + 1][y + 1];
		if(r == 3) return vis[x][y] + vis[x + 1][y] + vis[x + 1][y + 1];
		if(r == 4) return vis[x][y] + vis[x + 1][y] + vis[x + 1][y - 1];
	}
	if(tp == 2){
		if(use[2]) return 1;
		if(r == 1) return vis[x][y] + vis[x][y + 1] + vis[x][y + 2] + vis[x][y + 3];
		if(r == 2) return vis[x][y] + vis[x + 1][y] + vis[x + 2][y] + vis[x + 3][y];
	}
	if(tp == 3){
		if(use[3]) return 1;
		if(r == 1) return vis[x][y] + vis[x + 1][y] + vis[x][y + 1] + vis[x][y + 2];
		if(r == 2) return vis[x][y] + vis[x][y + 1] + vis[x][y + 2] + vis[x + 1][y + 2];
		if(r == 3) return vis[x][y] + vis[x + 1][y] + vis[x + 2][y] + vis[x + 2][y + 1];
		if(r == 4) return vis[x][y] + vis[x + 1][y] + vis[x + 2][y] + vis[x + 2][y - 1];
		if(r == 5) return vis[x][y] + vis[x + 1][y] + vis[x + 1][y + 1] + vis[x + 1][y + 2];
		if(r == 6) return vis[x][y] + vis[x + 1][y] + vis[x + 1][y - 1] + vis[x + 1][y - 2];
		if(r == 7) return vis[x][y] + vis[x][y + 1] + vis[x + 1][y] + vis[x + 2][y];
		if(r == 8) return vis[x][y] + vis[x][y + 1] + vis[x + 1][y + 1] + vis[x + 2][y + 1];
	}
	if(tp == 4){
		if(use[4]) return 1;
		return vis[x][y] + vis[x + 1][y] + vis[x][y + 1] + vis[x + 1][y + 1];
	}
	if(tp == 5){
		if(use[5]) return 1;
		if(r == 1) return vis[x][y] + vis[x + 1][y] + vis[x + 2][y] + vis[x + 2][y + 1] + vis[x + 2][y + 2];
		if(r == 2) return vis[x][y] + vis[x + 1][y] + vis[x + 2][y] + vis[x + 2][y - 1] + vis[x + 2][y - 2];
		if(r == 3) return vis[x][y] + vis[x][y + 1] + vis[x][y + 2] + vis[x + 1][y] + vis[x + 2][y];
		if(r == 4) return vis[x][y] + vis[x][y + 1] + vis[x][y + 2] + vis[x + 1][y + 2] + vis[x + 2][y + 2];
	}
	if(tp == 6){
		if(use[6]) return 1;
		if(r == 1) return vis[x][y] + vis[x][y + 1] + vis[x + 1][y + 1] + vis[x][y + 2] + vis[x][y + 3];
		if(r == 2) return vis[x][y] + vis[x][y + 1] + vis[x][y + 2] + vis[x + 1][y + 2] + vis[x][y + 3];
		if(r == 3) return vis[x][y] + vis[x + 1][y] + vis[x + 1][y - 1] + vis[x + 1][y + 1] + vis[x + 1][y + 2];
		if(r == 4) return vis[x][y] + vis[x + 1][y] + vis[x + 1][y - 1] + vis[x + 1][y - 2] + vis[x + 1][y + 1];
		if(r == 5) return vis[x][y] + vis[x + 1][y] + vis[x + 1][y + 1] + vis[x + 2][y] + vis[x + 3][y];
		if(r == 6) return vis[x][y] + vis[x + 1][y] + vis[x + 1][y - 1] + vis[x + 2][y] + vis[x + 3][y];
		if(r == 7) return vis[x][y] + vis[x + 1][y] + vis[x + 2][y] + vis[x + 2][y + 1] + vis[x + 3][y];
		if(r == 8) return vis[x][y] + vis[x + 1][y] + vis[x + 2][y] + vis[x + 2][y - 1] + vis[x + 3][y];
	}
	if(tp == 7){
		if(use[7]) return 1;
		if(r == 1) return vis[x][y] + vis[x + 1][y] + vis[x][y + 1] + vis[x][y + 2] + vis[x + 1][y + 2];
		if(r == 2) return vis[x][y] + vis[x + 1][y] + vis[x + 1][y + 1] + vis[x + 1][y + 2] + vis[x][y + 2];
		if(r == 3) return vis[x][y] + vis[x][y + 1] + vis[x + 1][y] + vis[x + 2][y] + vis[x + 2][y + 1];
		if(r == 4) return vis[x][y] + vis[x][y + 1] + vis[x + 1][y + 1] + vis[x + 2][y + 1] + vis[x + 2][y];
	}
	if(tp == 8){
		if(use[8]) return 1;
		if(r == 1) return vis[x][y] + vis[x + 1][y] + vis[x + 1][y + 1] + vis[x][y + 1] + vis[x][y + 2];
		if(r == 2) return vis[x][y] + vis[x][y + 1] + vis[x][y + 2] + vis[x + 1][y + 1] + vis[x + 1][y + 2];
		if(r == 3) return vis[x][y] + vis[x + 1][y] + vis[x][y + 1] + vis[x + 1][y + 1] + vis[x + 1][y + 2];
		if(r == 4) return vis[x][y] + vis[x + 1][y] + vis[x + 1][y - 1] + vis[x + 1][y + 1] + vis[x][y + 1];
		if(r == 5) return vis[x][y] + vis[x + 1][y] + vis[x + 2][y] + vis[x + 1][y + 1] + vis[x + 2][y + 1];
		if(r == 6) return vis[x][y] + vis[x + 1][y] + vis[x + 2][y] + vis[x + 1][y - 1] + vis[x + 2][y - 1];
		if(r == 7) return vis[x][y] + vis[x + 1][y] + vis[x + 2][y] + vis[x][y + 1] + vis[x + 1][y + 1];
		if(r == 8) return vis[x][y] + vis[x + 1][y] + vis[x][y + 1] + vis[x + 1][y + 1] + vis[x + 2][y + 1];
	}
	if(tp == 9){
		if(use[9]) return 1;
		if(r == 1) return vis[x][y] + vis[x][y + 1] + vis[x][y + 2] + vis[x + 1][y + 2] + vis[x + 1][y + 3];
		if(r == 2) return vis[x][y] + vis[x + 1][y] + vis[x + 1][y - 1] + vis[x][y + 1] + vis[x][y + 2];
		if(r == 3) return vis[x][y] + vis[x][y + 1] + vis[x + 1][y] + vis[x + 1][y - 1] + vis[x + 1][y - 2];
		if(r == 4) return vis[x][y] + vis[x][y + 1] + vis[x + 1][y + 1] + vis[x + 1][y + 2] + vis[x + 1][y + 3];
		if(r == 5) return vis[x][y] + vis[x + 1][y] + vis[x + 2][y] + vis[x + 2][y + 1] + vis[x + 3][y + 1];
		if(r == 6) return vis[x][y] + vis[x + 1][y] + vis[x + 2][y] + vis[x + 2][y - 1] + vis[x + 3][y - 1];
		if(r == 7) return vis[x][y] + vis[x + 1][y] + vis[x + 1][y - 1] + vis[x + 2][y - 1] + vis[x + 3][y - 1];
		if(r == 8) return vis[x][y] + vis[x + 1][y] + vis[x + 1][y + 1] + vis[x + 2][y + 1] + vis[x + 3][y + 1];
	}
	if(tp == 10){
		if(use[10]) return 1;
		return vis[x][y] + vis[x + 1][y] + vis[x + 1][y - 1] + vis[x + 1][y + 1] + vis[x + 2][y];
	}
	if(tp == 11){
		if(use[11]) return 1;
		if(r == 1) return vis[x][y] + vis[x + 1][y] + vis[x + 1][y + 1] + vis[x + 2][y + 1] + vis[x + 2][y + 2];
		if(r == 2) return vis[x][y] + vis[x + 1][y] + vis[x + 1][y - 1] + vis[x + 2][y - 1] + vis[x + 2][y - 2];
		if(r == 3) return vis[x][y] + vis[x][y + 1] + vis[x + 1][y] + vis[x + 1][y - 1] + vis[x + 2][y - 1];
		if(r == 4) return vis[x][y] + vis[x][y + 1] + vis[x + 1][y + 1] + vis[x + 1][y + 2] + vis[x + 2][y + 2];
	}
	if(tp == 12){
		if(use[12]) return 1;
		if(r == 1) return vis[x][y] + vis[x + 1][y] + vis[x][y + 1] + vis[x][y + 2] + vis[x][y + 3];
		if(r == 2) return vis[x][y] + vis[x][y + 1] + vis[x][y + 2] + vis[x][y + 3] + vis[x + 1][y + 3];
		if(r == 3) return vis[x][y] + vis[x + 1][y] + vis[x + 1][y + 1] + vis[x + 1][y + 2] + vis[x + 1][y + 3];
		if(r == 4) return vis[x][y] + vis[x + 1][y] + vis[x + 1][y - 1] + vis[x + 1][y - 2] + vis[x + 1][y - 3];
		if(r == 5) return vis[x][y] + vis[x][y + 1] + vis[x + 1][y] + vis[x + 2][y] + vis[x + 3][y];
		if(r == 6) return vis[x][y] + vis[x][y + 1] + vis[x + 1][y + 1] + vis[x + 1][y + 2] + vis[x + 1][y + 3];
		if(r == 7) return vis[x][y] + vis[x + 1][y] + vis[x + 2][y] + vis[x + 3][y] + vis[x + 3][y + 1];
		if(r == 8) return vis[x][y] + vis[x + 1][y] + vis[x + 2][y] + vis[x + 3][y] + vis[x + 3][y - 1];
	}
}

IL void Dfs(RG int xx, RG int yy){
	if(yy > xx) xx++, yy = 1;
	if(xx > 10) Out();
	if(vis[xx + G][yy + G]){
		Dfs(xx, yy + 1);
		return;
	}
	RG int x = xx + G, y = yy + G;
	if(!Check(xx, yy, 1, 1)){
		vis[x][y] = vis[x + 1][y] = vis[x][y + 1] = 1;
		use[1] = 1;
		Dfs(xx, yy + 1);
		use[1] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x][y + 1] = 0;
	}
	if(!Check(xx, yy, 1, 2)){
		vis[x][y] = vis[x][y + 1] = vis[x + 1][y + 1] = 1;
		use[1] = 1;
		Dfs(xx, yy + 1);
		use[1] = 0;
		vis[x][y] = vis[x][y + 1] = vis[x + 1][y + 1] = 0;
	}
	if(!Check(xx, yy, 1, 3)){
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y + 1] = 1;
		use[1] = 1;
		Dfs(xx, yy + 1);
		use[1] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y + 1] = 0;
	}
	if(!Check(xx, yy, 1, 4)){
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y - 1] = 1;
		use[1] = 1;
		Dfs(xx, yy + 1);
		use[1] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y - 1] = 0;
	}
	if(!Check(xx, yy, 2, 1)){
		vis[x][y] = vis[x][y + 1] = vis[x][y + 2] = vis[x][y + 3] = 2;
		use[2] = 1;
		Dfs(xx, yy + 1);
		use[2] = 0;
		vis[x][y] = vis[x][y + 1] = vis[x][y + 2] = vis[x][y + 3] = 0;
	}
	if(!Check(xx, yy, 2, 2)){
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 3][y] = 2;
		use[2] = 1;
		Dfs(xx, yy + 1);
		use[2] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 3][y] = 0;
	}
	if(!Check(xx, yy, 3, 1)){
		vis[x][y] = vis[x + 1][y] = vis[x][y + 1] = vis[x][y + 2] = 3;
		use[3] = 1;
		Dfs(xx, yy + 1);
		use[3] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x][y + 1] = vis[x][y + 2] = 0;
	}
	if(!Check(xx, yy, 3, 2)){
		vis[x][y] = vis[x][y + 1] = vis[x][y + 2] = vis[x + 1][y + 2] = 3;
		use[3] = 1;
		Dfs(xx, yy + 1);
		use[3] = 0;
		vis[x][y] = vis[x][y + 1] = vis[x][y + 2] = vis[x + 1][y + 2] = 0;
	}
	if(!Check(xx, yy, 3, 3)){
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 2][y + 1] = 3;
		use[3] = 1;
		Dfs(xx, yy + 1);
		use[3] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 2][y + 1] = 0;
	}
	if(!Check(xx, yy, 3, 4)){
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 2][y - 1] = 3;
		use[3] = 1;
		Dfs(xx, yy + 1);
		use[3] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 2][y - 1] = 0;
	}
	if(!Check(xx, yy, 3, 5)){
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y + 1] = vis[x + 1][y + 2] = 3;
		use[3] = 1;
		Dfs(xx, yy + 1);
		use[3] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y + 1] = vis[x + 1][y + 2] = 0;
	}
	if(!Check(xx, yy, 3, 6)){
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y - 1] = vis[x + 1][y - 2] = 3;
		use[3] = 1;
		Dfs(xx, yy + 1);
		use[3] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y - 1] = vis[x + 1][y - 2] = 0;
	}
	if(!Check(xx, yy, 3, 7)){
		vis[x][y] = vis[x][y + 1] = vis[x + 1][y] = vis[x + 2][y] = 3;
		use[3] = 1;
		Dfs(xx, yy + 1);
		use[3] = 0;
		vis[x][y] = vis[x][y + 1] = vis[x + 1][y] = vis[x + 2][y] = 0;
	}
	if(!Check(xx, yy, 3, 8)){
		vis[x][y] = vis[x][y + 1] = vis[x + 1][y + 1] = vis[x + 2][y + 1] = 3;
		use[3] = 1;
		Dfs(xx, yy + 1);
		use[3] = 0;
		vis[x][y] = vis[x][y + 1] = vis[x + 1][y + 1] = vis[x + 2][y + 1] = 0;
	}
	if(!Check(xx, yy, 4, 1)){
		vis[x][y] = vis[x + 1][y] = vis[x][y + 1] = vis[x + 1][y + 1] = 4;
		use[4] = 1;
		Dfs(xx, yy + 1);
		use[4] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x][y + 1] = vis[x + 1][y + 1] = 0;
	}
	if(!Check(xx, yy, 5, 1)){
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 2][y + 1] = vis[x + 2][y + 2] = 5;
		use[5] = 1;
		Dfs(xx, yy + 1);
		use[5] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 2][y + 1] = vis[x + 2][y + 2] = 0;
	}
	if(!Check(xx, yy, 5, 2)){
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 2][y - 1] = vis[x + 2][y - 2] = 5;
		use[5] = 1;
		Dfs(xx, yy + 1);
		use[5] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 2][y - 1] = vis[x + 2][y - 2] = 0;
	}
	if(!Check(xx, yy, 5, 3)){
		vis[x][y] = vis[x][y + 1] = vis[x][y + 2] = vis[x + 1][y] = vis[x + 2][y] = 5;
		use[5] = 1;
		Dfs(xx, yy + 1);
		use[5] = 0;
		vis[x][y] = vis[x][y + 1] = vis[x][y + 2] = vis[x + 1][y] = vis[x + 2][y] = 0;
	}
	if(!Check(xx, yy, 5, 4)){
		vis[x][y] = vis[x][y + 1] = vis[x][y + 2] = vis[x + 1][y + 2] = vis[x + 2][y + 2] = 5;
		use[5] = 1;
		Dfs(xx, yy + 1);
		use[5] = 0;
		vis[x][y] = vis[x][y + 1] = vis[x][y + 2] = vis[x + 1][y + 2] = vis[x + 2][y + 2] = 0;
	}
	if(!Check(xx, yy, 6, 1)){
		vis[x][y] = vis[x][y + 1] = vis[x + 1][y + 1] = vis[x][y + 2] = vis[x][y + 3] = 6;
		use[6] = 1;
		Dfs(xx, yy + 1);
		use[6] = 0;
		vis[x][y] = vis[x][y + 1] = vis[x + 1][y + 1] = vis[x][y + 2] = vis[x][y + 3] = 0;
	}
	if(!Check(xx, yy, 6, 2)){
		vis[x][y] = vis[x][y + 1] = vis[x][y + 2] = vis[x + 1][y + 2] = vis[x][y + 3] = 6;
		use[6] = 1;
		Dfs(xx, yy + 1);
		use[6] = 0;
		vis[x][y] = vis[x][y + 1] = vis[x][y + 2] = vis[x + 1][y + 2] = vis[x][y + 3] = 0;
	}
	if(!Check(xx, yy, 6, 3)){
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y - 1] = vis[x + 1][y + 1] = vis[x + 1][y + 2] = 6;
		use[6] = 1;
		Dfs(xx, yy + 1);
		use[6] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y - 1] = vis[x + 1][y + 1] = vis[x + 1][y + 2] = 0;
	}
	if(!Check(xx, yy, 6, 4)){
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y - 1] = vis[x + 1][y - 2] = vis[x + 1][y + 1] = 6;
		use[6] = 1;
		Dfs(xx, yy + 1);
		use[6] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y - 1] = vis[x + 1][y - 2] = vis[x + 1][y + 1] = 0;
	}
	if(!Check(xx, yy, 6, 5)){
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y + 1] = vis[x + 2][y] = vis[x + 3][y] = 6;
		use[6] = 1;
		Dfs(xx, yy + 1);
		use[6] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y + 1] = vis[x + 2][y] = vis[x + 3][y] = 0;
	}
	if(!Check(xx, yy, 6, 6)){
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y - 1] = vis[x + 2][y] = vis[x + 3][y] = 6;
		use[6] = 1;
		Dfs(xx, yy + 1);
		use[6] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y - 1] = vis[x + 2][y] = vis[x + 3][y] = 0;
	}
	if(!Check(xx, yy, 6, 7)){
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 2][y + 1] = vis[x + 3][y] = 6;
		use[6] = 1;
		Dfs(xx, yy + 1);
		use[6] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 2][y + 1] = vis[x + 3][y] = 0;
	}
	if(!Check(xx, yy, 6, 8)){
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 2][y - 1] = vis[x + 3][y] = 6;
		use[6] = 1;
		Dfs(xx, yy + 1);
		use[6] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 2][y - 1] = vis[x + 3][y] = 0;
	}
	if(!Check(xx, yy, 7, 1)){
		vis[x][y] = vis[x + 1][y] = vis[x][y + 1] = vis[x][y + 2] = vis[x + 1][y + 2] = 7;
		use[7] = 1;
		Dfs(xx, yy + 1);
		use[7] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x][y + 1] = vis[x][y + 2] = vis[x + 1][y + 2] = 0;
	}
	if(!Check(xx, yy, 7, 2)){
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y + 1] = vis[x + 1][y + 2] = vis[x][y + 2] = 7;
		use[7] = 1;
		Dfs(xx, yy + 1);
		use[7] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y + 1] = vis[x + 1][y + 2] = vis[x][y + 2] = 0;
	}
	if(!Check(xx, yy, 7, 3)){
		vis[x][y] = vis[x][y + 1] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 2][y + 1] = 7;
		use[7] = 1;
		Dfs(xx, yy + 1);
		use[7] = 0;
		vis[x][y] = vis[x][y + 1] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 2][y + 1] = 0;
	}
	if(!Check(xx, yy, 7, 4)){
		vis[x][y] = vis[x][y + 1] = vis[x + 1][y + 1] = vis[x + 2][y + 1] = vis[x + 2][y] = 7;
		use[7] = 1;
		Dfs(xx, yy + 1);
		use[7] = 0;
		vis[x][y] = vis[x][y + 1] = vis[x + 1][y + 1] = vis[x + 2][y + 1] = vis[x + 2][y] = 0;
	}
	if(!Check(xx, yy, 8, 1)){
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y + 1] = vis[x][y + 1] = vis[x][y + 2] = 8;
		use[8] = 1;
		Dfs(xx, yy + 1);
		use[8] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y + 1] = vis[x][y + 1] = vis[x][y + 2] = 0;
	}
	if(!Check(xx, yy, 8, 2)){
		vis[x][y] = vis[x][y + 1] = vis[x][y + 2] = vis[x + 1][y + 1] = vis[x + 1][y + 2] = 8;
		use[8] = 1;
		Dfs(xx, yy + 1);
		use[8] = 0;
		vis[x][y] = vis[x][y + 1] = vis[x][y + 2] = vis[x + 1][y + 1] = vis[x + 1][y + 2] = 0;
	}
	if(!Check(xx, yy, 8, 3)){
		vis[x][y] = vis[x + 1][y] = vis[x][y + 1] = vis[x + 1][y + 1] = vis[x + 1][y + 2] = 8;
		use[8] = 1;
		Dfs(xx, yy + 1);
		use[8] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x][y + 1] = vis[x + 1][y + 1] = vis[x + 1][y + 2] = 0;
	}
	if(!Check(xx, yy, 8, 4)){
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y - 1] = vis[x + 1][y + 1] = vis[x][y + 1] = 8;
		use[8] = 1;
		Dfs(xx, yy + 1);
		use[8] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y - 1] = vis[x + 1][y + 1] = vis[x][y + 1] = 0;
	}
	if(!Check(xx, yy, 8, 5)){
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 1][y + 1] = vis[x + 2][y + 1] = 8;
		use[8] = 1;
		Dfs(xx, yy + 1);
		use[8] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 1][y + 1] = vis[x + 2][y + 1] = 0;
	}
	if(!Check(xx, yy, 8, 6)){
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 1][y - 1] = vis[x + 2][y - 1] = 8;
		use[8] = 1;
		Dfs(xx, yy + 1);
		use[8] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 1][y - 1] = vis[x + 2][y - 1] = 0;
	}
	if(!Check(xx, yy, 8, 7)){
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x][y + 1] = vis[x + 1][y + 1] = 8;
		use[8] = 1;
		Dfs(xx, yy + 1);
		use[8] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x][y + 1] = vis[x + 1][y + 1] = 0;
	}
	if(!Check(xx, yy, 8, 8)){
		vis[x][y] = vis[x + 1][y] = vis[x][y + 1] = vis[x + 1][y + 1] = vis[x + 2][y + 1] = 8;
		use[8] = 1;
		Dfs(xx, yy + 1);
		use[8] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x][y + 1] = vis[x + 1][y + 1] = vis[x + 2][y + 1] = 0;
	}
	if(!Check(xx, yy, 9, 1)){
		vis[x][y] = vis[x][y + 1] = vis[x][y + 2] = vis[x + 1][y + 2] = vis[x + 1][y + 3] = 9;
		use[9] = 1;
		Dfs(xx, yy + 1);
		use[9] = 0;
		vis[x][y] = vis[x][y + 1] = vis[x][y + 2] = vis[x + 1][y + 2] = vis[x + 1][y + 3] = 0;
	}
	if(!Check(xx, yy, 9, 2)){
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y - 1] = vis[x][y + 1] = vis[x][y + 2] = 9;
		use[9] = 1;
		Dfs(xx, yy + 1);
		use[9] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y - 1] = vis[x][y + 1] = vis[x][y + 2] = 0;
	}
	if(!Check(xx, yy, 9, 3)){
		vis[x][y] = vis[x][y + 1] = vis[x + 1][y] = vis[x + 1][y - 1] = vis[x + 1][y - 2] = 9;
		use[9] = 1;
		Dfs(xx, yy + 1);
		use[9] = 0;
		vis[x][y] = vis[x][y + 1] = vis[x + 1][y] = vis[x + 1][y - 1] = vis[x + 1][y - 2] = 0;
	}
	if(!Check(xx, yy, 9, 4)){
		vis[x][y] = vis[x][y + 1] = vis[x + 1][y + 1] = vis[x + 1][y + 2] = vis[x + 1][y + 3] = 9;
		use[9] = 1;
		Dfs(xx, yy + 1);
		use[9] = 0;
		vis[x][y] = vis[x][y + 1] = vis[x + 1][y + 1] = vis[x + 1][y + 2] = vis[x + 1][y + 3] = 0;
	}
	if(!Check(xx, yy, 9, 5)){
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 2][y + 1] = vis[x + 3][y + 1] = 9;
		use[9] = 1;
		Dfs(xx, yy + 1);
		use[9] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 2][y + 1] = vis[x + 3][y + 1] = 0;
	}
	if(!Check(xx, yy, 9, 6)){
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 2][y - 1] = vis[x + 3][y - 1] = 9;
		use[9] = 1;
		Dfs(xx, yy + 1);
		use[9] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 2][y - 1] = vis[x + 3][y - 1] = 0;
	}
	if(!Check(xx, yy, 9, 7)){
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y - 1] = vis[x + 2][y - 1] = vis[x + 3][y - 1] = 9;
		use[9] = 1;
		Dfs(xx, yy + 1);
		use[9] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y - 1] = vis[x + 2][y - 1] = vis[x + 3][y - 1] = 0;
	}
	if(!Check(xx, yy, 9, 8)){
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y + 1] = vis[x + 2][y + 1] = vis[x + 3][y + 1] = 9;
		use[9] = 1;
		Dfs(xx, yy + 1);
		use[9] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y + 1] = vis[x + 2][y + 1] = vis[x + 3][y + 1] = 0;
	}
	if(!Check(xx, yy, 10, 1)){
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y - 1] = vis[x + 1][y + 1] = vis[x + 2][y] = 10;
		use[10] = 1;
		Dfs(xx, yy + 1);
		use[10] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y - 1] = vis[x + 1][y + 1] = vis[x + 2][y] = 0;
	}
	if(!Check(xx, yy, 11, 1)){
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y + 1] = vis[x + 2][y + 1] = vis[x + 2][y + 2] = 11;
		use[11] = 1;
		Dfs(xx, yy + 1);
		use[11] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y + 1] = vis[x + 2][y + 1] = vis[x + 2][y + 2] = 0;
	}
	if(!Check(xx, yy, 11, 2)){
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y - 1] = vis[x + 2][y - 1] = vis[x + 2][y - 2] = 11;
		use[11] = 1;
		Dfs(xx, yy + 1);
		use[11] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y - 1] = vis[x + 2][y - 1] = vis[x + 2][y - 2] = 0;
	}
	if(!Check(xx, yy, 11, 3)){
		vis[x][y] = vis[x][y + 1] = vis[x + 1][y] = vis[x + 1][y - 1] = vis[x + 2][y - 1] = 11;
		use[11] = 1;
		Dfs(xx, yy + 1);
		use[11] = 0;
		vis[x][y] = vis[x][y + 1] = vis[x + 1][y] = vis[x + 1][y - 1] = vis[x + 2][y - 1] = 0;
	}
	if(!Check(xx, yy, 11, 4)){
		vis[x][y] = vis[x][y + 1] = vis[x + 1][y + 1] = vis[x + 1][y + 2] = vis[x + 2][y + 2] = 11;
		use[11] = 1;
		Dfs(xx, yy + 1);
		use[11] = 0;
		vis[x][y] = vis[x][y + 1] = vis[x + 1][y + 1] = vis[x + 1][y + 2] = vis[x + 2][y + 2] = 0;
	}
	if(!Check(xx, yy, 12, 1)){
		vis[x][y] = vis[x + 1][y] = vis[x][y + 1] = vis[x][y + 2] = vis[x][y + 3] = 12;
		use[12] = 1;
		Dfs(xx, yy + 1);
		use[12] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x][y + 1] = vis[x][y + 2] = vis[x][y + 3] = 0;
	}
	if(!Check(xx, yy, 12, 2)){
		vis[x][y] = vis[x][y + 1] = vis[x][y + 2] = vis[x][y + 3] = vis[x + 1][y + 3] = 12;
		use[12] = 1;
		Dfs(xx, yy + 1);
		use[12] = 0;
		vis[x][y] = vis[x][y + 1] = vis[x][y + 2] = vis[x][y + 3] = vis[x + 1][y + 3] = 0;
	}
	if(!Check(xx, yy, 12, 3)){
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y + 1] = vis[x + 1][y + 2] = vis[x + 1][y + 3] = 12;
		use[12] = 1;
		Dfs(xx, yy + 1);
		use[12] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y + 1] = vis[x + 1][y + 2] = vis[x + 1][y + 3] = 0;
	}
	if(!Check(xx, yy, 12, 4)){
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y - 1] = vis[x + 1][y - 2] = vis[x + 1][y - 3] = 12;
		use[12] = 1;
		Dfs(xx, yy + 1);
		use[12] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 1][y - 1] = vis[x + 1][y - 2] = vis[x + 1][y - 3] = 0;
	}
	if(!Check(xx, yy, 12, 5)){
		vis[x][y] = vis[x][y + 1] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 3][y] = 12;
		use[12] = 1;
		Dfs(xx, yy + 1);
		use[12] = 0;
		vis[x][y] = vis[x][y + 1] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 3][y] = 0;
	}
	if(!Check(xx, yy, 12, 6)){
		vis[x][y] = vis[x][y + 1] = vis[x + 1][y + 1] = vis[x + 1][y + 2] = vis[x + 1][y + 3] = 12;
		use[12] = 1;
		Dfs(xx, yy + 1);
		use[12] = 0;
		vis[x][y] = vis[x][y + 1] = vis[x + 1][y + 1] = vis[x + 1][y + 2] = vis[x + 1][y + 3] = 0;
	}
	if(!Check(xx, yy, 12, 7)){
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 3][y] = vis[x + 3][y + 1] = 12;
		use[12] = 1;
		Dfs(xx, yy + 1);
		use[12] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 3][y] = vis[x + 3][y + 1] = 0;
	}
	if(!Check(xx, yy, 12, 8)){
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 3][y] = vis[x + 3][y - 1] = 12;
		use[12] = 1;
		Dfs(xx, yy + 1);
		use[12] = 0;
		vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = vis[x + 3][y] = vis[x + 3][y - 1] = 0;
	}
}

int in[30][30];

IL int Size(RG int x, RG int y){
	if(vis[x + G][y + G] || in[x][y]) return 0;
	RG int ret = 1;
	in[x][y] = 1;
	ret += Size(x + 1, y);
	ret += Size(x - 1, y);
	ret += Size(x, y - 1);
	ret += Size(x, y + 1);
	return ret;
}

int main(RG int argc, RG char* argv[]){
	Fill(vis, 1);
	for(RG int i = 1; i <= 10; ++i)
		for(RG int j = 1; j <= i; ++j){
			RG char c; scanf(" %c", &c);
			if(c == '.') vis[i + G][j + G] = 0;
			else vis[i + G][j + G] = c - 'A' + 1, use[c - 'A' + 1] = 1;
		}
	for(RG int i = 1; i <= 10; ++i)
		for(RG int j = 1; j <= i; ++j)
			if(!vis[i + G][j + G] && !in[i][j] && Size(i, j) < 3) return puts("No solution"), 0;
	Dfs(1, 1), puts("No solution");
    return 0;
}

posted @ 2018-02-27 21:00  Cyhlnj  阅读(187)  评论(0编辑  收藏  举报