Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- // 2xn tiling 2
- /*
- The number of way to fill the 2xn tile with 1x2, 2x1, 2x2
- input (1<= n <=1,000)
- go(n) = go(n - 1) + go(n - 2) + go(n - 2);
- go(0) = 1
- go(1) = 1
- go(2) = 3
- go(3) = go(2) + go(1) + go(1) = 3 + 1 + 1 = 5
- */
- int memo[1001];
- int go(int n) {
- if (n == 0) return 1;
- if (n == 1) return 1;
- if (n == 2) return 3;
- if (memo[n] > 0) return memo[n];
- memo[n] = (go(n - 1) + go(n - 2) + 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