Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <set>
- #include <bitset>
- #include <algorithm>
- #include <cstring>
- using namespace std;
- int budget;
- int x;
- int cena [1000];
- int stranici [1000];
- int dp[1000] [100000];
- int rec (int i, int m){
- int answer=-1e9 ; //1-e9 = 1 / 10^9
- if (i == x)
- return 0;
- if(dp[i][m] != -1)
- return dp[i][m];
- if(cena[i] <= m){
- answer = max(answer, rec(i+1,m-cena[i]) + stranici[i]);
- }
- answer = max(answer, rec(i+1,m));
- dp[i][m] = answer;
- return answer;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- memset(dp, -1, sizeof dp);
- cin >> x >> budget ;
- for(int i =0;i <x; i++){
- cin >> cena[i];
- }
- for (int i =0;i <x;i++){
- cin >> stranici[i];
- }
- cout << rec(0,budget);
- }
Advertisement
Add Comment
Please, Sign In to add comment