Cod sursa(job #2854533)
| Utilizator | Data | 21 februarie 2022 14:45:33 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.56 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int m[2][10010];
int main()
{
int n, g;
fin>>n>>g;
for(int i = 1; i <= n; i++){
int w, p;
fin>>w>>p;
for(int j = 1; j <= g; j++){
m[1][j] = m[0][j];
if(j >= w){
m[1][j] = max(m[0][j], m[0][j - w] + p);
}
}
for(int j = 1; j <= g; j++){
m[0][j] = m[1][j];
}
}
fout<<m[1][g];
return 0;
}
