Cod sursa(job #2791101)
Utilizator | Data | 30 octombrie 2021 09:19:50 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("rucsac.in");
ofstream fout ("rucsac.out");
int n,maxV;
int dp[10005];
int main()
{
fin>>n>>maxV;
for(int i=1;i<=n;i++)
{
int x,p;
fin>>x>>p;
for(int val=maxV; val>=1; val--)
if(val >= x)
dp[val]=max(dp[val], dp[val-x] + p);
}
fout<<dp[maxV];
return 0;
}