【題解】ZeroJudge c139: 00291 – The House Of Santa Claus

題目敘述:https://zerojudge.tw/ShowProblem?problemid=c139

#include <iostream>
using namespace std;

int a[6][6];

void func(int count, int last, int path){
    if (count < 9){
        for(int i = 1; i < 6; i++){
            if (last != i && a[last][i] == 0){
                a[last][i] = 1;
                a[i][last] = 1;
                func(count+1, i, path*10+i);
                a[last][i] = 0;
                a[i][last] = 0;
            }
        }
    }else if (count == 9){
        cout << path << "\n";
    }
}

int main(){
    for (int i = 1; i < 6; i++){
        for (int j = 1; j < 6; j++){
            a[i][j] = 0;
        }
    }
    a[1][4] = 1;
    a[4][1] = 1;
    a[2][4] = 1;
    a[4][2] = 1;
    func(1, 1, 1);
}
分享本文 Share with friends