状态转移方程
dp[i] = dp[i-1] + dp[i-2]
前提是dp[i-1]不是-1,dp[i-2]不是-1
代码
java
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
long mod = (long)1e9+7;
long[] dp = new long[100010];
int N = s.nextInt();
int M = s.nextInt();
for(int i=0;i<M;i++)
dp[s.nextInt()]=-1;
dp[0]=1;
for(int i=1;i<=N;i++){
if(dp[i]==-1)
continue;
if(i>=1 && dp[i-1]!=-1)
dp[i] = (dp[i]+dp[i-1])%mod;
if(i>=2 && dp[i-2]!=-1)
dp[i] = (dp[i]+dp[i-2])%mod;
}
if(dp[N]==-1)//这个测试点很无语
System.out.println(0);
else
System.out.println(dp[N]);
s.close();
}
}