Guest User

Untitled

a guest
Jan 17th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // 2xn tiling 2
  5.  
  6. /*
  7. The number of way to fill the 2xn tile with 1x2, 2x1, 2x2
  8. input (1<= n <=1,000)
  9.  
  10. go(n) = go(n - 1) + go(n - 2) + go(n - 2);
  11. go(0) = 1
  12. go(1) = 1
  13. go(2) = 3
  14. go(3) = go(2) + go(1) + go(1) = 3 + 1 + 1 = 5
  15. */
  16.  
  17. int memo[1001];
  18.  
  19. int go(int n) {
  20. if (n == 0) return 1;
  21. if (n == 1) return 1;
  22. if (n == 2) return 3;
  23.  
  24. if (memo[n] > 0) return memo[n];
  25.  
  26. memo[n] = (go(n - 1) + go(n - 2) + go(n - 2)) % 10007;
  27. return memo[n];
  28. }
  29.  
  30. int main(void) {
  31.  
  32. int n;
  33. cin >> n;
  34. cout << go(n) << endl;
  35.  
  36. return 0;
  37. }
Add Comment
Please, Sign In to add comment