01-08 08:57
Recent Posts
Recent Comments
๊ด€๋ฆฌ ๋ฉ”๋‰ด

miinsun

[Algorithm]์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ž๋ฐ”_60 ์กฐํ•ฉ์˜ ๊ฒฝ์šฐ ์ˆ˜(๋ฉ”๋ชจ์ด์ œ์ด์…˜) ๋ณธ๋ฌธ

Algorithm/Java

[Algorithm]์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ž๋ฐ”_60 ์กฐํ•ฉ์˜ ๊ฒฝ์šฐ ์ˆ˜(๋ฉ”๋ชจ์ด์ œ์ด์…˜)

miinsun 2022. 3. 3. 00:07

 

๐Ÿ’ฌ ๋ฌธ์ œ ์„ค๋ช…

์กฐํ•ฉ์˜ ๊ฒฝ์šฐ ์ˆ˜๋Š” ์œ„์˜ ๊ณต์‹์œผ๋กœ ๊ณ„์‚ฐ๋ฉ๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ ์—ฌ๋Ÿฌ๋ถ„์€ ์ด ๊ณต์‹์„ ์“ฐ์ง€์•Š๊ณ  ๋‹ค์Œ ๊ณต์‹์„ ์‚ฌ์šฉํ•˜์—ฌ ์žฌ๊ท€๋ฅผ ์ด์šฉํ•ด ์กฐํ•ฉ์ˆ˜๋ฅผ ๊ตฌํ•ด์ฃผ๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์„ธ์š”.

 

๐Ÿ”จ ์ž…์ถœ๋ ฅ ์˜ˆ

 

์ž…๋ ฅ - ์ฒซ์งธ ์ค„์— ์ž์—ฐ์ˆ˜ n(3<=n<=33)๊ณผ r(0<=r<=n)์ด ์ž…๋ ฅ๋ฉ๋‹ˆ๋‹ค.

์˜ˆ์‹œ ์ž…๋ ฅ 1)

5 3

์˜ˆ์‹œ ์ž…๋ ฅ 2)

33 19

 

์ถœ๋ ฅ - ์ฒซ์งธ ์ค„์— ์กฐํ•ฉ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ์‹œ ์ถœ๋ ฅ 1)

10

์˜ˆ์‹œ ์ถœ๋ ฅ 2)

818809200
 
 

 

 

โœจ ์•„์ด๋””์–ด

โ€‹

 

 

๐Ÿ’ป Solution.java

import java.util.*;

public class Main {
	int[][] dy = new int [35][35];
	
	public int DFS(int n, int r) {
		if(dy[n][r] != 0 ) return dy[n][r];
		if(n == r || r == 0) return 1;
		else return dy[n][r] = DFS (n - 1, r - 1) + DFS(n - 1, r);
 	}
	
	public static void main(String[] args){
		Main main = new Main();
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int r = sc.nextInt();
		
		System.out.println(main.DFS(n, r));
		sc.close();
		return ;
	}
}

 

Comments