IMohammedNasr

Untitled

Apr 27th, 2022
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. void solve()
  2. {
  3.     int n, m;
  4.     cin >> n >> m;
  5.     int dp[n+1] = {};
  6.     dp[0] = 1;
  7.     dp[1] = 1;
  8.  
  9.     for (int i=0; i<m; i++)
  10.     {
  11.         int x;
  12.         cin >> x;
  13.         dp[x] = -1;
  14.     }
  15.  
  16.     for (int i=2; i<=n; i++)
  17.     {
  18.         if (~dp[i])
  19.         {
  20.             if(~dp[i-1]) dp[i] = (dp[i] + dp[i-1])%mod;
  21.             if(~dp[i-2]) dp[i] = (dp[i] + dp[i-2])%mod;
  22.         }
  23.     }
  24.     cout << max(0, dp[n]);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment