Cod sursa(job #2818479)
Utilizator | Data | 16 decembrie 2021 10:09:36 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("rucsac.in");
ofstream g("rucsac.out");
int dp[10001], n, gr;
void read()
{
f>>n>>gr;
int x, y, maxim = 0;
for(int i = 1;i <= n;++i)
{
f>>x>>y;
for(int j = gr - x;j >= 0;--j)
dp[j + x] = max(dp[j + x], dp[j] + y), maxim = max(maxim, dp[j + x]);
}
g<<maxim;
}
int main()
{
read();
return 0;
}