Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
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
Tags
more
Archives
Today
Total
관리 메뉴

코드와이

[BAEKJOON] 1010. 다리놓기 본문

acmicpc

[BAEKJOON] 1010. 다리놓기

코드와이 2021. 4. 13. 23:26

 

DP, 조합

문제링크

www.acmicpc.net/problem/1010

 

1010번: 다리 놓기

입력의 첫 줄에는 테스트 케이스의 개수 T가 주어진다. 그 다음 줄부터 각각의 테스트케이스에 대해 강의 서쪽과 동쪽에 있는 사이트의 개수 정수 N, M (0 < N ≤ M < 30)이 주어진다.

www.acmicpc.net

 

package acmicpc.Silver5;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class 다리놓기 {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		
		int T = Integer.parseInt(br.readLine());
		
		for(int tc = 0 ; tc < T ; tc++) {
			
			st = new StringTokenizer(br.readLine());
			
			int n = Integer.parseInt(st.nextToken());
			int m = Integer.parseInt(st.nextToken());
			
			int[][] dp = new int[n+1][m+1];
			
			for(int i = 1 ; i <= m ; i++) {
				dp[1][i] = i;
			}
			for(int i = 2 ; i <= n ; i++) {
				for(int j = 1 ; j <= m ; j++) {
					dp[i][j] = dp[i][j-1] + dp[i-1][j-1];
				}
			}
			
			System.out.println(dp[n][m]);
		}
	}
}

'acmicpc' 카테고리의 다른 글

[BAEKJOON] 17471. 게리맨더링  (0) 2021.04.13
[BAEKJOON] 14501. 퇴사  (0) 2021.04.13
[BAEKJOON] 1238. 파티  (0) 2021.04.12
[BAEKJOON] 1261. 알고스팟  (0) 2021.04.12
[BAEKJOON] 1916. 최소비용 구하기  (0) 2021.04.12