problem description Everyone knows " Super Marie " is a very good jumping explorer, his forte is jumping, but it can only leap forward one or two steps at a time. Once, he had to pass a long n trail, the path of M traps, these traps are located in the integer position, respectively, is A1,A2,.... am, into which will be dead. Obviously, if there were two traps next to each other, Mary would have to jump at it anyway. Now give the length of the path n, the number and location of the trap. Find out how many methods of jumping can reach the shore of victory (arrival N), starting at position 1. Input format first behavior two integers n,m second behavior m integer that represents the location of the trap output format an integer. A sample of the number of scenarios that Mary jumps to n input 412 sample output 1 data size and conventions >=n >=3, m>=1 n>m; Traps are not located on 1 and N
Code with the problem
#include <iostream> #include <cmath>using namespace std;int n;int a[100];int b[100];int ans=0;void dfs (int i) {if (i==n) {ans++;} else{for (int j=0;j<pow (2,n); j + +) {if (b[j]!=1) {if (b[j+1]==0) DFS (i+1); Elsedfs (i+2);}}} int main () {int m;cin>>n;cin>>m;for (int i=0;i<m;i++) {cin>>a[i];b[a[i]]=1;} DFS (0); return 0;}
Recursion--Algorithm improvement-Super Marie