[Blue Bridge Cup] [algorithm improves VIP] Super Mario

[Blue Bridge Cup] [algorithm improves VIP] Super Mario

Time limit: 1Sec Memory Limit: 128MB submit: 1 Solution: 1

Title Description

We all know that "Super Mario" is a very good jump explorer, his specialty is the jump, but it can only jump one or two steps forward. On one occasion, he has to go through a long trail of n, the trail has m traps, which are located at integer position, namely, a1, a2, .... am, which fall into the certain death. Obviously, if there are two next to the trap, then jump Mary is in any case make life difficult. 
Now given path length n, the number and placement of these traps. Mary obtained from position 1 to start, how many kinds of jump method to reach the shore of victory (reach the position n). 

Data size and Conventions 
40> = n> =. 3, m> = 1 
n> m; 
on the trap 1 is not located, and n 
 

Entry

The first two acts of integers n, m 
second behavior integer m represents the position of the trap 

Export

An integer. N represents the number jumps to program Mary 

Sample input

4  1 
2 

Sample Output

1
#include<iostream>
#include<cstring>
using namespace std;
int a[49],ans;
void dfs( int s, int e  ){
	 if( s > e ){
	 	 return ;
	 }
	 if( s == e ){
	 	 ans++;
	     return ;
	 }
	 
	 if( !a[s+1]  ){
	 	 dfs(s+1,e);
	 }
	 
	 if( !a[s+2] ){
	 	 dfs(s+2,e);
	 }
	 
}
int main(void){
	int n,m;
	while( scanf("%d%d",&n,&m)!=EOF){
		   memset(a,0,sizeof(a));
		   for( int i=1;i<=m;i++){
		   	    int t;
		   	    scanf("%d",&t);
		   	    a[t] = 1;
		   }
		   ans= 0;
		   dfs( 1,n);
		   printf("%d\n",ans);
	}
	
	return 0;
}

 

Guess you like

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