다이니믹 프로그래밍을 이용하는 문제 n,n에는 0 값이 들어있느니 자기자신을 계산하는 것을 방지하기 위해 continue 코드를 넣어준다.


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>
#include <algorithm>
using namespace std;
int d[105][105];
int a[105][105];
int n;
 
int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
    {
        cin >> a[i][j];
    }
    d[1][1= 1;
    for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
    {
        if (a[i][j] == 0)
            continue;
        int jump = a[i][j];
        if (j + jump <= n)
            d[i][j + jump] += d[i][j];
        if (i + jump <= n)
            d[i + jump][j] += d[i][j];
    }
    cout << d[n][n] << endl;
    return 0;
}
cs


'백준 온라인 저지' 카테고리의 다른 글

백준 2293: 동전 1  (0) 2018.08.04
백준 10942: 팰린드롬?  (0) 2018.07.31
백준 11048: 이동하기  (0) 2018.07.31
백준 2263: 트리의 순회  (0) 2018.07.31
백준 1931: 회의실 배정  (0) 2018.07.30

+ Recent posts