UVA 7508황후·(2)+예처리+귀속

4840 단어 귀속수색하다
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include 
#include
#include 

using namespace std;

typedef unsigned long long ULL;

int book[3][20];
int sol[100][10];
int temp[10];
int l=0,k=0;

void dfs(int cur)
{
    if(cur==8)
    {
        for(int i=0;i<8;i++)
            sol[l][i]=temp[i];
        l++;
        return ;
    }
    for(int i=0;i<8;i++)
    {
        if(!book[0][i]&&!book[1][cur+i+1]&&!book[2][cur-i+8])
        {
            temp[cur]=i;
            book[0][i]=book[1][cur+i+1]=book[2][cur-i+8]=1;
            dfs(cur+1);
            book[0][i]=book[1][cur+i+1]=book[2][cur-i+8]=0;
        }
    }
}


int main()
{
    dfs(0);
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        scanf("%d%d",&n,&m);
        printf("SOLN       COLUMN
"
); printf(" # 1 2 3 4 5 6 7 8

"
); int no=0; for(int i=0;iif(sol[i][m-1]==n-1) { printf("%2d ",++no); for(int j=0;j<8;j++) printf(" %d",sol[i][j]+1); cout<printf("
"
); } return 0; } /* */

좋은 웹페이지 즐겨찾기