MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / f

Function f

CSES/DP/BookShop_MEMO.cpp:28–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26ostream &operator<<(ostream &ostream, const vector<T> &c) { for (auto &it : c) { cout << it << " "; } return ostream; }
27
28int f(int idx, int tar, vector<ll> &cost, vector<ll> &weight,vector<vector<ll>> &dp) {
29 if (idx == 0) {
30 if (tar >= cost[0]) return weight[0];
31 return 0;
32 }
33 if (dp[idx][tar] != -1) return dp[idx][tar];
34 int notake = f(idx-1,tar,cost,weight,dp);
35 int take = 0;
36 if (tar >= cost[idx]) take = f(idx-1,tar - cost[idx], cost, weight,dp) + weight[idx];
37 return dp[idx][tar] = max(take , notake);
38}
39
40void solve() {
41 int n, x; cin >> n >> x;

Callers 1

solveFunction · 0.70

Calls 1

maxFunction · 0.50

Tested by

no test coverage detected