baekjoon 1890

호진·2023년 4월 1일
0

baekjoon

목록 보기
27/37


Idea

dynamic programming
recurrence relation -- board[N - 1][N - 1]


Code

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

long long board[101][101] = { 0, };
long long dp[101][101] = { 0, };

// dynamic programming
// recurrence relation - board[N - 1][N - 1]

int main(void) {
	int N;
	scanf("%d", &N);

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			scanf("%d", &board[i][j]);
		}
	}

	dp[0][0] = 1;

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			int leap = board[i][j];

			if (i != (N - 1) && (i + leap) < N) {
				dp[i + leap][j] += dp[i][j];
			}
			if (j != (N - 1) && (j + leap) < N) {
				dp[i][j + leap] += dp[i][j];
			}
		}
	}
	
	printf("%lld", dp[N - 1][N- 1]);

	return 0;
}
profile
💭(。•̀ᴗ-)✧

0개의 댓글