티스토리 뷰

PS

[백준(BOJ) 15749번] Snow Boots 풀이

yonsweng 2020. 1. 26. 11:01

t[i] : i번 타일에 도착할 수 있으면 true, 없으면 false.

부츠를 1번부터 순서대로 신어보면서 t[i]를 채워가면 된다.

 

for 1 <= j <= B:

    1 <= k <= d[j]를 만족하는 어떤 k에 대해, t[i-k]가 true이면서 i-k번 타일과 i번 타일에서 j번 부츠를 신을 수 있는 경우 t[i] = true.

#include <iostream>

using namespace std;

int main() {
    int N, B, f[251], s[251], d[251];
    cin >> N >> B;
    for (int i = 1; i <= N; i++) cin >> f[i];
    for (int j = 1; j <= B; j++) cin >> s[j] >> d[j];

    bool t[251] = {false, true,};  // t[1] = true;
    int j;
    for (j = 1; j <= B; j++) {
        for (int i = 1; i <= N; i++) {
            if (s[j] >= f[i]) {  // If he can wear boots j on tile i.
                bool able = false;
                for (int k = 1; k <= d[j] && i - k >= 1; k++) {
                    if (t[i - k] && s[j] >= f[i - k]) {  // If he can wear boots j on tile i-k.
                        able = true;
                        break;
                    }
                }
                t[i] |= able;
            }
        }
        if (t[N]) break;
    }

    cout << j - 1;

    return 0;
}
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/05   »
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 31
글 보관함