-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11060.cpp
More file actions
49 lines (41 loc) · 751 Bytes
/
11060.cpp
File metadata and controls
49 lines (41 loc) · 751 Bytes
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
38
39
40
41
42
43
44
45
46
47
48
49
//
// 11060.cpp
// algo
//
// Created by 박효정 on 2021/05/22.
//
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
int arr[1001];
int n;
int dp[1001]={2147000000,};
int main(){
cin.tie(0);
cout.tie(0);
std::ios::sync_with_stdio(false);
cin>>n;
for(int i=0;i<n;i++){
cin>>arr[i];
}
for(int i=0;i<n;i++){
dp[i]=2147000000;
}
dp[0]=0;
for(int i=0;i<n;i++){
for(int j=i+1;j<=i+arr[i];j++){
if(j>=n)
break;
dp[j]=min(dp[j],dp[i]+1);
}
}
if(dp[n-1]==2147000000){
cout<<-1<<"\n";
}
else{
cout<<dp[n-1]<<"\n";
}
return 0;
}