Notice
Recent Posts
Recent Comments
Link
«   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
Archives
Today
Total
관리 메뉴

hwooo

BOJ (C/C++) 14494번: 다이나믹이 뭐예요? 본문

Study/Algorithm

BOJ (C/C++) 14494번: 다이나믹이 뭐예요?

hwooo 2022. 11. 25. 03:56

풀이

D[i][j]에 도달하는 경우의 수는 →, ↓, ↘의 세 방향에서 오는 경우의 수의 합이다.

코드

#include <stdio.h>

unsigned int DP[1001][1001];
int main() {
	int n, m;
	scanf("%d %d", &n, &m);

	for (int i = 1; i <= 1000; i++) DP[i][1] = DP[1][i] = 1;

	for (int i = 2; i <= n; i++) {
		for (int j = 2; j <= m; j++) {
			DP[i][j] = (DP[i - 1][j - 1] + DP[i][j - 1] + DP[i - 1][j])%1000000007;
		}
	}
	printf("%d", DP[n][m]);
	return 0;
}