[DP] 25706번 - 자전거 묘기

안수진·2023년 10월 4일

Baekjoon

목록 보기
4/55
post-thumbnail

🔗 문제 링크

백준 25706번 - 자전거 묘기

📝 풀이

public class 자전거묘미_25706 {

	public static void run(int n, int[] heights) {
		
		int [] result = new int[n];
		
		for(int i = n-1; i >= 0; i--) {
			
			int step = i + heights[i] + 1;
			
			if(step >= n) {
				result[i] = 1;
			}
			else {
				result[i] = result[step] + 1;
			}
		}
		
		for(int num: result) {
			System.out.print(num + " ");
		}
		
	}
	
	
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		
		int n = Integer.parseInt(st.nextToken());
		
		st = new StringTokenizer(br.readLine());
		int[] heights = new int[n];
		
		for(int i = 0; i < n; i++) {
			heights[i] = Integer.parseInt(st.nextToken());
		}
		
		run(n, heights);

	}
profile
항상 궁금해하기

0개의 댓글