#include <iostream> #include <algorithm> #include <queue> #include <string.h> using namespace std; int map[510][510]; int dp[510][510]; int row, col; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, -1, 1}; int safe(int x, int y) { if(x >= 0 && y >= 0 && x < row && y < col) { return 1; } else { return 0; } } int DFS(int x, int y) { if(x == row-1 && y == col-1) { return 1; } if(dp[x][y] != -1) { return dp[x][y]; } dp[x][y] = 0; for(int i = 0; i < 4; i++) { int xpos = x+dx[i]; int ypos = y+dy[i]; if(safe(xpos, ypos) == 1) { if(map[x][y] > map[xpos][ypos]) { dp[x][y] += DFS(xpos, ypos); } } } return dp[x][y]; } int main(void) { // freopen("B1520_input.txt", "r", stdin); cin >> row >> col; for(int i = 0; i < row; i++) { for(int j = 0; j < col; j++) { cin >> map[i][j]; dp[i][j] = -1; } } cout << DFS(0, 0); return 0; } | cs |
'Baekjoon > DP' 카테고리의 다른 글
[백준 11051] 이항 계수 2 (DP) (C/C++) (0) | 2020.03.17 |
---|---|
[백준 2186] 문자판 (DFS, DP) (C/C++) (★★★) (0) | 2020.03.17 |
[백준 1937] 욕심쟁이 판다 (DFS, DP) (C/C++) (★) (0) | 2020.03.16 |
[백준 1309] 동물원 (DP) (C/C++) (★★) (0) | 2020.03.16 |
[백준 1965] 상자 넣기 (DP) (C/C++) (0) | 2020.03.16 |