Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using std::cin;
  6. using std::cout;
  7.  
  8. int main() {
  9.     size_t rows;
  10.     size_t columns;
  11.     cin >> rows >> columns;
  12.     std::vector<std::vector<size_t>> matrix(
  13.         rows,
  14.         std::vector<size_t>(columns));
  15.     for (size_t i = 0; i != rows; ++i) {
  16.         for (size_t j = 0; j != columns; ++j) {
  17.             if (i == 0 && j == 0) {
  18.                 matrix[i][j] = 1;
  19.             } else {
  20.                 if (i >= 2 && j >= 1) {
  21.                     matrix[i][j] += matrix[i - 2][j - 1];
  22.                 }
  23.                 if (i >= 1 && j >= 2) {
  24.                     matrix[i][j] += matrix[i - 1][j - 2];
  25.                 }
  26.             }
  27.         }
  28.     }
  29.     cout << matrix[rows - 1][columns - 1] << std::endl;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement