Advertisement
Josif_tepe

Untitled

Mar 17th, 2022
861
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <algorithm>
  6. #include <set>
  7. #include <cstring>
  8. using namespace std;
  9. typedef long long ll;
  10. int films, days, passed;
  11. ll dp[200][200];
  12. ll rec(int days_left, int films_left) {
  13.     if(days_left == 0 and films_left == 0) {
  14.         return 1;
  15.     }
  16.     if(days_left == 0) {
  17.         return 0;
  18.     }
  19.     if(dp[days_left][films_left] != -1) {
  20.         return dp[days_left][films_left];
  21.     }
  22.     ll ret = 0;
  23.     ll MOD = 1e9 + 7;
  24.     ret += (rec(days_left - 1, films_left - 1) % MOD) * (ll) (films - films_left + 1);
  25.     ret %= MOD;
  26.     ret += rec(days_left - 1, films_left) * max(0LL, (ll) (films_left - passed));
  27.     ret %= MOD;
  28.     return dp[days_left][films_left] = ret % MOD;
  29. }
  30. int main(){
  31.     ios_base::sync_with_stdio(false);
  32.     cin >> films >> days >> passed;
  33.     memset(dp, -1, sizeof dp);
  34.     cout << rec(days, films) << endl;
  35.     return 0;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement