Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- // 2xn Tiling
- /*
- : The num of way to fill the tile
- Let's D(n) : number of way to fill (2xn)
- way 1) which use (1xn) => D(n-2)
- way 2) which use (2x1) => D(n-1)
- so, D(n) = D(n-1) + D(n-2)
- D(0) = 0;
- D(1) = 1;
- D(2) = 2;
- */
- //(STK1) : I missed again by D(n) = D(n-1) + 1 + D(n-2) + 1,
- //becuase I thought it as operation count.
- int memo[1001];
- int go(int n) {
- if (n <= 2) return n;
- if (memo[n] > 0) return memo[n];
- memo[n] = (go(n - 1) + go(n - 2)) % 10007;
- return memo[n];
- }
- int main(void) {
- int n;
- cin >> n;
- cout << go(n) << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment