leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0879.cpp (659B)
0 class Solution { 1 public: 2 int profitableSchemes(int n, int minProfit, const vector<int> &group, const vector<int> &profit) { 3 int dp[101][101] = {{1}}; 4 int res = 0, mod = 1e9 + 7; 5 for (int k = 0; k < group.size(); k++) { 6 int g = group[k], p = profit[k]; 7 for (int i = minProfit; i >= 0; i--) { 8 for (int j = n - g; j >= 0; j--) { 9 int &cache = dp[min(i + p, minProfit)][j + g]; 10 cache = (cache + dp[i][j]) % mod; 11 } 12 } 13 } 14 for (int x : dp[minProfit]) 15 res = (res + x) % mod; 16 return res; 17 } 18 };