본문 바로가기

알고리즘/구현 및 시뮬레이션

[B10752] - Cow Hopscotch

https://www.acmicpc.net/problem/10752

재귀를 활용해서 이동시키면서 목적지에 도달하면 ans를 1씩 증가시키며

경우의 수를 세어주면 됩니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
using namespace std;
char a[16][16];
int r, c;
int ans = 0;
void move(int x, int y, char temp)
{
    if (x == r - && y == c - 1)
    {
        ans++;
        return;
    }
    for (int i = x + 1; i < r; i++)
    {
        for (int j = y + 1; j < c; j++)
        {
            if (a[i][j] == temp)
                continue;
            move(i, j, a[i][j]);
        }
    }
}
int main()
{
    cin >> r >> c;
    for (int i = 0; i < r; i++)
        cin >> a[i];
    move(00, a[0][0]);
    cout << ans << '\n';
}
cs

'알고리즘 > 구현 및 시뮬레이션' 카테고리의 다른 글

[B9573] - Combination Lock  (0) 2018.09.23
[B10675] - Cow Routing  (0) 2018.09.23
[B10025] - 게으른 백곰  (0) 2018.09.22
[B10656] - 십자말풀이  (0) 2018.09.21
[B9873] - Cow Baseball  (0) 2018.09.21