Study/알고리즘 문제풀이
백준 14501. 퇴사 :: 돼지개발자
돼지개발자
2019. 1. 16. 16:52
출저 : https://www.acmicpc.net/problem/14501
"시뮬레이션"
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 32 33 34 35 36 37 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { static int N; static int map[][]; static int max = 0; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); N = Integer.parseInt(br.readLine()); map = new int[N+1][2]; for (int i = 1; i <= N; i++) { StringTokenizer st = new StringTokenizer(br.readLine()); map[i][0] = Integer.parseInt(st.nextToken()); map[i][1] = Integer.parseInt(st.nextToken()); } solve(1,0); System.out.println(max); } static void solve(int idx, int sum) { for (int i = idx; i <= N; i++) { if(i + map[i][0] > N+1) continue; solve(i + map[i][0], sum + map[i][1]); } max = Math.max(max, sum); } } | cs |