Cod sursa(job #2662918)
| Utilizator | Data | 24 octombrie 2020 20:29:55 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.44 kb |
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int n,maxw,dp[10005];
struct obiect
{
int weight,profit;
}wp;
int main()
{
fin>>n>>maxw;
for(int i=1;i<=n;i++)
{
fin>>wp.weight>>wp.profit;
for(int j=maxw;j>=wp.weight;j--)
dp[j]=max((dp[j-wp.weight]+wp.profit),dp[j]);
}
fout<<dp[maxw];
return 0;
}
