Cod sursa(job #3033004)
| Utilizator | Data | 23 martie 2023 11:03:19 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 65 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <fstream>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
struct obiect{
int p;
int w;
}v[5005];
int dp[5005];
int main()
{ int n, G;
fin>>n>>G;
for(int i=1; i<=n; i++)
fin>>v[i].w>>v[i].p;
for(int i=1; i<=n; i++)
for(int g=G; g>=1; g--){
if(g-v[i].w<0)
dp[g]=dp[g];
else
dp[g]=max(dp[g-v[i].w]+v[i].p, dp[g]);
}
fout<<dp[G];
return 0;
}
