add: 231014
This commit is contained in:
parent
bde1ceb0c2
commit
de11fa9dc3
|
|
@ -0,0 +1,23 @@
|
|||
#include "defs.h"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
|
||||
int LC231014::paintWalls(const std::vector<int>& cost, const std::vector<int>& time) {
|
||||
int n = cost.size();
|
||||
|
||||
std::unordered_map<int, int> ans;
|
||||
std::function<int(int, int)> dp = [&](int pos, int rem_free) {
|
||||
if (pos + rem_free >= n)
|
||||
return 0;
|
||||
if (pos == n - 1)
|
||||
return (rem_free + time[pos] < 0) ? 0x70000000 : cost[pos];
|
||||
// rem_free < (1 << 21)
|
||||
int& ret = ans[((rem_free + 505 * 505) << 10) | pos];
|
||||
return ret ? ret : ret = std::min(dp(pos + 1, rem_free + time[pos]) + cost[pos], dp(pos + 1, rem_free - 1));
|
||||
};
|
||||
|
||||
return dp(0, 0);
|
||||
}
|
||||
|
||||
using Solution = LC231014;
|
||||
|
|
@ -31,4 +31,9 @@ public:
|
|||
static std::string decodeAtIndex(const std::string& s, int k);
|
||||
};
|
||||
|
||||
class LC231014 {
|
||||
public:
|
||||
static int paintWalls(const std::vector<int>&, const std::vector<int>&);
|
||||
};
|
||||
|
||||
#endif //LEETCODE_CPP_DEFS_H
|
||||
|
|
|
|||
Loading…
Reference in New Issue