There was an error while loading. Please reload this page.
1 parent 0a2bf94 commit 056da4eCopy full SHA for 056da4e
code/790.多米诺和托米诺平铺.cpp
@@ -0,0 +1,41 @@
1
+/*
2
+ * @lc app=leetcode.cn id=790 lang=cpp
3
+ *
4
+ * [790] 多米诺和托米诺平铺
5
+ */
6
+#include <map>
7
+using namespace std;
8
+// @lc code=start
9
+class Solution {
10
+ int max_value = 1000000007;
11
+ map<int, int> cache;
12
+public:
13
+ int numTilings(int n) {
14
+ if (n == 0) {
15
+ return 1;
16
+ }
17
+
18
+ if (cache.count(n) > 0) {
19
+ return cache.at(n);
20
21
22
+ long x = 0;
23
+ x += numTilings(n - 1);
24
+ if (n >= 2) {
25
+ x += numTilings(n - 2);
26
27
28
+ for (size_t i = 3; i <= n; i++) {
29
+ x += 2 * numTilings(n - i);
30
31
32
+ int r = (int)(x % max_value);
33
34
+ auto pr = make_pair(n, r);
35
36
+ cache.insert(pr);
37
+ return r;
38
39
+};
40
+// @lc code=end
41
0 commit comments