2015년 7월 29일 수요일

UVA291 The House Of Santa Claus

DFS, Graph

출처: UVA UVA291 The House Of Santa Claus

SOL)
오름차순으로 출력을 해야하니 다음으로 갈 수 있는 정점의 번호가 낮은 곳부터 탐색


cpp to html [-] Collapse
#include<iostream>
using namespace std;

int adj[6][6] = {
    {0,0,0,0,0,0},
    {0,0,1,1,0,1},
    {0,1,0,1,0,1},
    {0,1,1,0,1,1},
    {0,0,0,1,0,1},
    {0,1,1,1,1,0}
};
int visit[9];
void Euler(int here, int cnt){
    visit[cnt] = here;
    if (cnt == 8){
        for (int i = 0; i < 9; i++)
            cout << visit[i];
        cout << endl;
        return;
    }
    for (int there = 1; there < 6; there++){
        if (adj[here][there] > 0){
            adj[here][there]--;
            adj[there][here]--;
            Euler(there, cnt + 1);
            adj[here][there]++;
            adj[there][here]++;
        }
    }
}

int main(){
    Euler(1, 0);
    return 0;
}

댓글 없음:

댓글 쓰기