Blue Bridge: Super Mario

Super Mary

Problem Description

  Zoomed all know that " Super Mario " is very good at jumping explorers, he took the watch is a good show jumping, but it times can only jump forward step or two steps .
There times, he has to go through article ⻓ n is the ⽺ ⼩ intestinal tract, ⼩ channel has m number traps, which are located in the integer bit is set, namely A1, A2, ... .am,
Where the mortal trap START ⽆ suspect. Obviously, if there are two next to the trap, then Mary is also fires regardless of the hops make life difficult.
  ⼩ ⻓ now given channel of n- , number and placement of these traps. Mary obtained from position 1 to start, how many jumps Remedies to reach win benefit of the other side (to the position the n- ).
START input format
  The first ⾏ two integers n, m
  ⾏ second shot of m integers, indicates the position of the trap
Output Format
  
integers. Mary jump n represents the number of cases ⽅
Sample lose START
4 1
2
Sample Output
1
Scale data and conventions
  40>= n>= 3,m>= 1
  n>m;
  Trap will not be located 1 and n on
Analysis: ⾯ similar problems on that road stairs and leetcode, but be aware that climbing stairs is a ⻓ n degrees,
           ⽽ from individual cases from one sent to n, n-long ⾛ - ⻓ 1 degree, it is initialized V [1] = 1, V [2], if the trap is not 1, there is a trap is 0,
           Then according to state transition process ⽅ V [I] = V [I - . 1] + V [I - 2]; determined value v [n] is the number of species ~~~

 

 

#include <iostream>
#include <vector>
using namespace std;
int main() {
 int n, m;
 cin >> n >> m;
 vector<int> v(n+1, -1);
 for(int i = 0; i < m; i++) {
     int temp;
     cin >> temp;
     v[temp] = 0;
 }
 v[1] = 1;
 v[2] = v[2] == 0 ? v[2] : 1;
 for(int i = 3; i <= n; i++) {
     if( v[i] != 0)
         v[i] = v[i-1] + v[i-2];
 }
 cout << v[n];
 return 0; 
}

 

Published 736 original articles · won praise 123 · views 80000 +

Guess you like

Origin blog.csdn.net/S_999999/article/details/103392647