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