Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <algorithm>
- #include <vector>
- #include <algorithm>
- #include <set>
- #include <cstring>
- #include <cmath>
- #include "cstring"
- using namespace std;
- int n,c;
- vector<pair<int ,int>> v;
- int memo[105][10005];
- int dp(int i,int coins_left){
- if(i == -1){
- return 0;
- }
- if(memo[i][coins_left] != -1){
- return memo[i][coins_left];
- }
- int res = -500;
- res = max(res,dp(i-1,coins_left));
- if(coins_left - v[i].second >= 0){
- res = max(res,dp(i-1,(coins_left -v[i].second)+ v[i].first)+1);
- }
- return memo[i][coins_left] =res;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin >> n >> c;
- for (int i = 0; i < c; i++) {
- int a,b;
- cin >> a >> b;
- v.push_back(make_pair(b,a));
- }
- sort(v.begin(),v.end());
- for (int i = 0; i < 105; i++) {
- for (int j = 0; j < 10005; j++) {
- memo[i][j] = -1;
- }
- }
- cout << dp(c-1,n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement