Advertisement
Josif_tepe

Untitled

Nov 24th, 2022
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <fstream>
  4. #include <algorithm>
  5. #include <cmath>
  6. using namespace std;
  7. int r,c,b,n;
  8. int memo[55][55][11];
  9. int df (int red,int kolona,int leftofn){
  10.     if(leftofn == 1 && red*kolona >= b){
  11.         return 1;
  12.     }
  13.     if(memo[red][kolona][leftofn] != -1){
  14.         return memo[red][kolona][leftofn];
  15.     }
  16.     int res = 0;
  17.     int mod = 1e9+7;
  18.     if(leftofn>1){
  19.         for (int i = 1; i < red; i++) {
  20.             if(i*kolona>= b){
  21.                 res +=( +df(red-i,kolona,leftofn-1)*2) % mod;
  22.                 res = res%mod;
  23.             }
  24.         }
  25.         for (int i = 1; i < kolona; i++) {
  26.             if(i*red >= b){
  27.                 res += (df(red,kolona-i,leftofn-1)*2) % mod;
  28.                 res = res%mod;
  29.             }
  30.         }
  31.     }
  32.     return memo[red][kolona][leftofn] = res;
  33. }
  34. int main(){
  35. int t;
  36. cin >> t;
  37. while(t--){
  38.     cin >> r >> c >> b >> n;
  39.     for (int i = 0; i <= 50; i++) {
  40.         for (int j = 0; j <= 50; j++) {
  41.             for (int k = 0; k < 11; k++) {
  42.                 memo[i][j][k] = -1;
  43.             }
  44.         }
  45.     }
  46.     cout << df(r,c,n) << endl;
  47. }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement