Algorithm/Baekjoon
[백준] 퇴사 - 14501 S3
Oxix
2022. 6. 29. 18:01
해당 문제는 브루트 포스 문제로 모든 경우를 다 탐색한 다음 합산한 값을 비교하여 출력하기로 하였다.
public class 퇴사_14501 { static int N; static Work[] arr; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; N = Integer.parseInt(br.readLine()); arr = new Work[N + 1]; for (int i = 1; i <= N; i++) { st = new StringTokenizer(br.readLine()); int T = Integer.parseInt(st.nextToken()); int P = Integer.parseInt(st.nextToken()); arr[i] = new Work(T, P); } int sum = 0; for (int i = 1; i <= N; i++) { sum = Math.max(sum, recursion(i + arr[i].T, arr[i].P)); } System.out.println(sum); } private static int recursion(int n, int s) { if (n > N + 1) return 0; int sum = s; for (int i = n; i <= N; i++) { sum = Math.max(sum, recursion(i + arr[i].T, s + arr[i].P)); } return sum; } static class Work { int T; int P; public Work(int T, int P) { this.T = T; this.P = P; } } }