Guest User

Untitled

a guest
Jan 17th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // 2xn Tiling
  5.  
  6. /*
  7. : The num of way to fill the tile
  8. Let's D(n) : number of way to fill (2xn)
  9.  
  10. way 1) which use (1xn) => D(n-2)
  11. way 2) which use (2x1) => D(n-1)
  12. so, D(n) = D(n-1) + D(n-2)
  13.  
  14. D(0) = 0;
  15. D(1) = 1;
  16. D(2) = 2;
  17. */
  18.  
  19. //(STK1) : I missed again by D(n) = D(n-1) + 1 + D(n-2) + 1,
  20. //becuase I thought it as operation count.
  21.  
  22. int memo[1001];
  23.  
  24. int go(int n) {
  25.  
  26. if (n <= 2) return n;
  27.  
  28. if (memo[n] > 0) return memo[n];
  29.  
  30. memo[n] = (go(n - 1) + go(n - 2)) % 10007;
  31.  
  32. return memo[n];
  33. }
  34.  
  35. int main(void) {
  36.  
  37. int n;
  38. cin >> n;
  39. cout << go(n) << endl;
  40.  
  41. return 0;
  42. }
Add Comment
Please, Sign In to add comment