解一个9*9的数独,行和列和普通数独一样需要出现1~9,但是它的小区域不是方形的,而是一个不规则的面积为9的图形。
DLX模版题。位运算和dfs处理小区域的边界就不说了。DLX搜解,搜到一个解以后继续搜,如果搜到第二个解则说明有多解,立即跳出。需要注意的是,搜到第一个解以后,需要保存解,不然继续搜索原来的解会被破坏。
#include <stdlib.h>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
#define ll long long
const int SLOT = 0;
const int ROW = 1;
const int COL = 2;
const int SUB = 3;
int encode(int type,int id,int num){
return type*81+(id-1)*9+num;
}
int mp[12][12];
int sub[12][12];
const int maxnode=270000;
const int maxn=350;
const int maxr=750;
int anscnt;
void init(){
anscnt=0;
memset(sub,0,sizeof(sub));
}
struct dlx{
#define FOR(i,A,s) for(i