add: 231015
This commit is contained in:
parent
de11fa9dc3
commit
c920f9bfd4
|
|
@ -0,0 +1,23 @@
|
|||
#include "defs.h"
|
||||
#include <vector>
|
||||
|
||||
constexpr static int MOD = 1'000'000'007;
|
||||
|
||||
int LC231015::numWays(int steps, int arrLen) {
|
||||
if (arrLen == 1)
|
||||
return 1;
|
||||
int n = std::min(arrLen, 505);
|
||||
int ans[2][512] {{1}, {}};
|
||||
for (int cs = 1; cs <= steps; ++cs) {
|
||||
ans[cs & 1][0] = (ans[cs & 1 ^ 1][0] + ans[cs & 1 ^ 1][1]) % MOD;
|
||||
for (int i = 1; i < n - 1; ++i)
|
||||
ans[cs & 1][i] = (
|
||||
(ans[cs & 1 ^ 1][i - 1] + ans[(cs & 1) ^ 1][i]) % MOD +
|
||||
ans[cs & 1 ^ 1][i + 1]
|
||||
) % MOD;
|
||||
ans[cs & 1][n - 1] = (ans[cs & 1 ^ 1][n - 2] + ans[cs & 1 ^ 1][n - 1]) % MOD;
|
||||
}
|
||||
return ans[steps & 1][0];
|
||||
}
|
||||
|
||||
using Solution = LC231015;
|
||||
|
|
@ -36,4 +36,9 @@ public:
|
|||
static int paintWalls(const std::vector<int>&, const std::vector<int>&);
|
||||
};
|
||||
|
||||
class LC231015 {
|
||||
public:
|
||||
static int numWays(int, int);
|
||||
};
|
||||
|
||||
#endif //LEETCODE_CPP_DEFS_H
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@
|
|||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::cout << LC230927::decodeAtIndex("a2b3c4d5e6f7g8h9", 9);
|
||||
std::cout << LC231015::numWays(4,2);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue