0%

HackerRank Warm-up 3.Jumping on the Clouds, in C++

題目連結:Jumping on the Clouds | HackerRank

基本DP

1
2
3
4
5
6
7
8
9
10
11
int jumpingOnClouds(vector<int> c) {
int dp[105];
fill(dp,dp+105,0x3f3f3f3f);
dp[0]=0;
if(c[1]==0) dp[1]=1;
for(int i=2;i<c.size();i++){
if(c[i]==0) dp[i]=min(dp[i-1],dp[i-2])+1;
else dp[i]=0x3f3f3f3f;
}
return dp[c.size()-1];
}