-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudy_2698.java
More file actions
31 lines (27 loc) · 826 Bytes
/
Study_2698.java
File metadata and controls
31 lines (27 loc) · 826 Bytes
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
import java.util.Scanner;
// Create by Inho 2018. 3. 8. 오후 2:11:45
// 2698 인접한 비트의 개수
public class Study_2698 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[][][] DP = new int[101][101][2];
for(int j=0;j<=100;j++){
for(int k=0;k<=100;k++){
DP[j][k][0] = DP[j][k][1]=0;
}
}
int TC = scanner.nextInt();
while(--TC>=0){
int N = scanner.nextInt();
int K = scanner.nextInt();
DP[1][0][0]=DP[1][0][1]=1; // 초기값 초기화. [1][0][0] = 0 , [1][0][1] = 1
for(int j=2;j<=N;j++){
for(int k=0;k<j;k++){ // 맨 뒤 값이 1일때만 ++;
DP[j][k][0] = DP[j-1][k][0] + DP[j-1][k][1];
DP[j][k][1] = DP[j-1][k][0] + ((k>=1)?DP[j-1][k-1][1]:0);
}
}
System.out.println(DP[N][K][0]+DP[N][K][1]);
}
}
}