Cod sursa(job #3252414)
| Utilizator | Data | 29 octombrie 2024 15:47:12 | |
|---|---|---|---|
| Problema | Submultimi | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <fstream>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
struct obj
{
int greutate, profit;
};
int main()
{
int dp[10001]={};
obj chestii[5001];
int n,gmax;
fin>>n>>gmax;
for(int i=1;i<=n;i++)
fin>>chestii[i].greutate>>chestii[i].profit;
for(int i=1;i<=n;i++)
{
for(int g=gmax;g>=chestii[i].greutate;g--)
dp[g]=max(dp[g-chestii[i].greutate]+chestii[i].profit,dp[g]);
}
fout<<dp[gmax];
return 0;
}
