Cod sursa(job #2279859)

Utilizator cristii2000cristiiPanaite Cristian cristii2000cristii Data 10 noiembrie 2018 09:54:38
Problema Problema rucsacului Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.45 kb
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;

ifstream in("rucsac.in");
ofstream out("rucsac.out");

int n, G;

int dp[10005];

int main() {

    ios::sync_with_stdio(false);

    in >> n >> G;
    int maxi = 0;

    for(int i = 1; i <= n; i++){
        int g, v;

        in >> g >> v;
        for(int j = G; j >= g; j--){
             dp[j] = max(dp[j], dp[j - g] + v);
        }
    }
    out << dp[G];

    return 0;
}