Cod sursa(job #2165159)

Utilizator RazvanGutaGuta Razvan Alexandru RazvanGuta Data 13 martie 2018 11:19:41
Problema Problema rucsacului Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.42 kb
#include<fstream>
using namespace std;
ifstream f("rucsac.in");
ofstream g("rucsac.out");
struct rucsac{
    int g,p;
}a[5001];
int n,G,sol[10001];
int main()
{
    f>>n>>G;
    for(int i=1;i<=n;i++)
        f>>a[i].g>>a[i].p;
    for(int i=1;i<=n;i++)
        for(int j=G-a[i].g;j>=0;j--)
            if(sol[j]+a[i].p>sol[j+a[i].g])
                sol[j+a[i].g]=sol[j]+a[i].p;
    g<<sol[G];
    return 0;
}