Raslboyy

3007

Sep 12th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     ifstream fin("input.txt");
  10.     ofstream fout("output.txt");
  11.  
  12.     int n, k;
  13.     fin >> n >> k;
  14.     vector<vector<vector<long long>>> dp(2 * n + 1, vector<vector<long long>>(2 * n + 1, vector<long long>(2*n + 1)));
  15.     dp[0][0][0] = 1;
  16.     for (int i = 0; i < 2 * n; i++)
  17.         for (int j = 0; j <= i; j++)
  18.             for (int g = 0; g <= i; g++) {
  19.                 dp[i + 1][j + 1][max(g, j + 1)] += dp[i][j][g];
  20.                 dp[i + 1][j + 1][max(g, j + 1)] %= 1000 * 1000 * 1000 + 7;
  21.                 if (j > 0) {
  22.                     dp[i + 1][j - 1][g] += dp[i][j][g];
  23.                     dp[i + 1][j - 1][max(g, j + 1)] %= 1000 * 1000 * 1000 + 7;
  24.                 }
  25.             }
  26.     fout << dp[2 * n][0][k] << endl;
  27.  
  28.     fin.close();
  29.     fout.close();
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment