코딩테스트/Baekjoon
[백준 9656] 돌 게임2 (DP)
주니어주니
2023. 8. 4. 19:21
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String answer = (n % 2 == 0) ? "SK" : "CY";
System.out.println(answer);
}
}
이게 되나 ? 하고 홀짝으로 나눠서 풀어봤는데 정답은 맞았지만 ...
DP 연습해야지
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] dp = new int[1001];
// 기본값 세팅 (상근승 = 0, 창영승 = 1)
dp[1] = 1;
dp[2] = 0;
dp[3] = 1;
// 1개 남았을 때, 3개 남았을 때 누가 이기는지 확인
for(int i=4; i<=n; i++) {
dp[i] = (dp[i - 3] == 1 && dp[i - 1] == 1) ? 0 : 1;
}
System.out.println(dp[n] == 0 ? "SK" : "CY");
}
}
* 기본값 세팅
* 점화식 세우기
* 가장 작은 값부터 채워가기