[프로그래머스 C++] 등굣길
[프로그래머스 C++] 등굣길
https://school.programmers.co.kr/learn/courses/30/lessons/42898
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
해결전략
동적계획법 Dynamic Programming
정답코드
#include <cmath> #include <vector> using namespace std; int solution(int m, int n, vector<vector<int>> puddles) { vector<vector<int>> v(n + 1, vector<int>(m + 1, 0)); for (int i = 0; i < puddles.size(); i++) { v[puddles[i][1]][puddles[i][0]] = -1; } v[1][1] = 1; for (int y = 1; y <= n; y++) { for (int x = 1; x <= m; x++) { if (y == 1 && x == 1) continue; if (v[y][x] == -1) continue; if (v[y - 1][x] == -1 && v[y][x - 1] == -1){ v[y][x] = 0; } else if (v[y - 1][x] == -1 && v[y][x - 1] != -1) { v[y][x] = v[y][x - 1]; } else if (v[y - 1][x] != -1 && v[y][x - 1] == -1) { v[y][x] = v[y - 1][x]; } else{ v[y][x] = (v[y - 1][x] + v[y][x - 1]) % 1000000007; } } } return v[n][m]; }
'⭐ 코딩테스트 > 프로그래머스' 카테고리의 다른 글
[프로그래머스 C++] 3 x n 타일링 (0) | 2024.04.22 |
---|---|
[프로그래머스 C++] 요격 시스템 (0) | 2024.04.05 |
[프로그래머스 C++] 조이스틱 (0) | 2024.04.01 |
[프로그래머스 C++] 숫자 블록 (0) | 2024.03.23 |
[프로그래머스 C++] 혼자서 하는 틱택토 (1) | 2024.03.22 |
댓글
이 글 공유하기
다른 글
-
[프로그래머스 C++] 3 x n 타일링
[프로그래머스 C++] 3 x n 타일링
2024.04.22 -
[프로그래머스 C++] 요격 시스템
[프로그래머스 C++] 요격 시스템
2024.04.05 -
[프로그래머스 C++] 조이스틱
[프로그래머스 C++] 조이스틱
2024.04.01 -
[프로그래머스 C++] 숫자 블록
[프로그래머스 C++] 숫자 블록
2024.03.23
댓글을 사용할 수 없습니다.