Notice
Recent Posts
문제 풀이 및 개발 공간
[백준] 11060번 점프점프 (silver 2 본문
import java.io.*;
import java.util.*;
public class Main{
public static void main(String[]args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
int n=Integer.valueOf(br.readLine());
int[] dp=new int[n+1];
int[] num=new int[n+1];
StringTokenizer st=new StringTokenizer(br.readLine());
Arrays.fill(dp,Integer.MAX_VALUE);
for(int i=1; i<=n; i++){
num[i]=Integer.valueOf(st.nextToken());
}
dp[1]=0;
for(int i=1; i<=n; i++){
if(dp[i]==Integer.MAX_VALUE){
continue;
}
for(int j=1; j<=num[i]; j++){
if(i+j<=n){
dp[i+j]=Math.min(dp[i+j], dp[i]+1);
}
}
}
bw.write(dp[n]==Integer.MAX_VALUE ? "-1" : dp[n]+"");
bw.flush();
}
}
'백준공부 > java' 카테고리의 다른 글
[백준] 2217번 로프 (silver 4 (2) | 2023.10.31 |
---|---|
[백준] 2167번 2차원 배열의 합 (silver 5 (0) | 2023.10.31 |
[백준] 2012번 등수매기기 (silver 3 (0) | 2023.10.29 |
[백준] 10825번 국영수 (silver 4 (0) | 2023.10.29 |
[백준] 1504번 특정한 최단 경로 (gold 4 (0) | 2023.10.22 |