leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1575.cpp (616B)


0 class Solution {
1 static const int MOD = 1E9 + 7;
2 int dp[101][201];
4 public:
5 Solution() { memset(dp, 0xFF, sizeof(dp)); }
7 int countRoutes(const vector<int> &loc, int start, int finish, int fuel) {
8 if (fuel < 0) return 0;
9 if (dp[start][fuel] >= 0) return dp[start][fuel];
11 int res = (start == finish);
12 for (int i = 0; i < loc.size(); i++) {
13 if (i == start) continue;
14 int solution = countRoutes(loc, i, finish, fuel - abs(loc[start] - loc[i]));
15 res = (res + solution) % MOD;
16 }
17 return dp[start][fuel] = res;
18 }
19 };