Cod sursa(job #2652343)
| Utilizator | Data | 24 septembrie 2020 18:57:48 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 50 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.59 kb |
#include<fstream>
#include<iostream>
#include <algorithm>
using namespace std;
ifstream f ("rucsac.in");
ofstream g("rucsac.out");
long long n,gmax,rasp;
long long matr[5001][10001];
int main()
{
f >> n >> gmax;
for(int i = 1;i<=n;i++)
{
long long gr,cost;
f >> gr>> cost;
for (int j=1; j<gr; j++)
{
matr[i][j]=matr[i-1][j];
}
for (int j=gr;j<=gmax; ++j)
{
matr[i][j] = max(matr[i-1][j], matr[i - 1][j - gr] + cost);
}
}
g << matr[n][gmax];
}
