Cod sursa(job #2554988)
Utilizator | Data | 23 februarie 2020 16:18:20 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include<fstream>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int n,g,w,p,i,j;
int dp[2][10001];
int main()
{
fin>>n>>g;
for(i=1; i<=n; i++)
{
fin>>w>>p;
for(j=1; j<=g; j++)
{
if(j>=w)
dp[1][j]=max(dp[0][j-w]+p,dp[0][j]);
else dp[1][j]=dp[0][j];
}
for(j=1;j<=g;j++)
dp[0][j]=dp[1][j];
}
fout<<dp[1][g];
}