Advertisement
paulomiranda98

Military Class - 2019 ICPC Malaysia National

Jan 30th, 2021
1,092
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define F first
  4. #define S second
  5. #define EB emplace_back
  6. #define INF 0x3f3f3f3f
  7. #define INFLL 0x3f3f3f3f3f3f3f3fLL
  8. #define all(x) x.begin(),x.end()
  9. #define endl '\n'
  10. #define W(x) cerr << "\033[31m"<<  #x << " = " << x << "\033[0m" << endl;
  11.  
  12. using namespace std;
  13.  
  14. typedef long long ll;
  15. typedef pair<int, int> pii;
  16. typedef pair<ll, ll> pll;
  17.  
  18. std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
  19.  
  20. const int MOD = 1000000007;
  21. const int MAXN = 2010;
  22.  
  23. int dp[MAXN][1<<10];
  24. bool mat[MAXN][MAXN];
  25.  
  26. int n, e;
  27. int solve(int i, int mask){
  28.     if(i == n)
  29.         return 1;
  30.     if(dp[i][mask] != -1)
  31.         return dp[i][mask];
  32.     int ans=0;
  33.     for(int k=-e; k<=e; k++){
  34.         if(i+k>=0 and i+k<n and ((mask&(1<<(e+k))) == 0) and !mat[i][i+k]){
  35.             ans = (ans + solve(i+1, (mask|(1<<(e+k)))>>1))%MOD;
  36.         }
  37.     }
  38.     return dp[i][mask] = ans;
  39. }
  40.  
  41. int main() {
  42.     memset(dp, -1, sizeof(dp));
  43.     ios_base::sync_with_stdio(false); cin.tie(NULL);
  44.     int k;
  45.     cin >> n >> e >> k;
  46.    
  47.     for(int i=0; i<k; i++){
  48.         int a, b;
  49.         cin >> a >> b;
  50.         a--;
  51.         b--;
  52.         mat[a][b] = true;
  53.     }
  54.    
  55.     cout << solve(0, 0) << endl;
  56.     return 0;
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement