Cod sursa(job #2769049)
| Utilizator | Data | 13 august 2021 12:31:14 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.62 kb |
#include <iostream>
#include <fstream>
using namespace std;
int n,g;
int dp[2][10005];
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int main()
{
int L=1;
int w,p;
fin>>n>>g;
for(int i=1; i<=n; i++,L=1-L)
{
fin>>w>>p;
for(int j=0; j<=g; j++)
{
dp[L][j]=dp[1-L][j];
if(j>=w)
{
dp[L][j]=max(dp[L][j],dp[1-L][j-w]+p);
}
}
}
L=1-L;
int maxim=0;
for(int i=0;i<=g;i++)
{
maxim=max(maxim,dp[L][i]);
}
fout<<maxim;
return 0;
}
