Cod sursa(job #3160893)

Utilizator bianca_ioanaGhetea Bianca bianca_ioana Data 25 octombrie 2023 11:18:09
Problema Problema rucsacului Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.14 kb
#include <fstream>

using namespace std;
ifstream fin ("rucsac.in");
ifstream fin ("rucsac.out");
const int maxn=5001;
const int maxg=10000;
struct tobject
{
  int greutate;
  int profit;
};
int memo [maxn][maxg];
int dpprofit (int idx, int capacitate, tobject, objs[])
{
    if(idx==0) return 0;
    if (capacitate==0) return 0;
    if (memo[idx][capacitate]!=0) return memo[idx][capacitate];
    if (objs[idx].greutate>capacitate)
    {
        memo[idx][capacitate]=dpprofit(idx-1, capacitate, objs);
        return memo[idx][capacitate];
    }
    int profit 1=dpprofit(idx-1, capacitate, objs);
    intnewcapacitate=capacitate-objs[idx].greutate;
    int profit2=onjs[idx].profit+dpprofit(idx-1, newcapacitate, objs);
    memo[idx][capacitate]=max(profit1, profit2);
    return memo[idx][capacitate];
}
int main()
{
    int nrelem;
    int maxgr;
    tobject objs[maxn];
    fin>>nrelem;
    fin>>maxgr;
    for (int i=1; i<=nrelem; i++)
    {
        int greutate;
        int profit;
        fin>>greutate;
        fin>>profit;
        tobject obj={greutate, profit};
        objs[i]=onjs;
    }
    return 0;
}