반응형
Notice
Recent Posts
Recent Comments
Link
지구정복
[DP] 백준 - 다리놓기 본문
728x90
반응형
-자바
package dp;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class BJ1010 {
private static BufferedWriter bw =
new BufferedWriter( new OutputStreamWriter(System.out));
private static int t, n, m;
private static int[][] d;
private static StringTokenizer st;
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
t = Integer.parseInt( br.readLine() );
for( int i=0; i<t; i++ ) {
st = new StringTokenizer( br.readLine() );
n = Integer.parseInt( st.nextToken() );
m = Integer.parseInt( st.nextToken() );
d = new int[m+1][];
for( int j=1; j<=m; j++ ) {
d[j] = new int[j+1];
for( int k=0; k<=j; k++ ) {
if( k==0 || k==j ) d[j][k] = 1;
else d[j][k] = d[j-1][k-1] + d[j-1][k];
}
}
bw.write( d[m][n] + "\n" );
bw.flush();
}
bw.close();
br.close();
}
}
-파이썬
t = int(input())
for i in range(0, t):
n, m = map(int, input().split())
d = [ [0] for _ in range(m+1) ]
for j in range( 1, m+1 ):
d[j] = [ 0 for _ in range( j+1 ) ]
for k in range( 0, j+1 ):
if k==0 or k==j:
d[j][k] = 1
else:
d[j][k] = d[j-1][k-1] + d[j-1][k]
print( d[m][n] )
728x90
반응형
'데이터 엔지니어링 정복 > Algorithm' 카테고리의 다른 글
[DP] 백준 - 내리막 길 (0) | 2021.07.17 |
---|---|
[수학] 백준 - 소수찾기 (0) | 2021.07.17 |
[DP] 백준 - 파스칼의 삼각형 (0) | 2021.07.16 |
[DP] 백준 - 타일 장식물 (0) | 2021.07.16 |
[DP] 백준 - BABBA (0) | 2021.07.16 |
Comments