Cod sursa(job #3297110)
Utilizator | Data | 21 mai 2025 11:45:54 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 50 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.57 kb |
#include <bits/stdc++.h>
#define nmax 1005
#define gmax 10005
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
struct ceva
{
int val,weight;
} v[nmax];
int n,Gmax;
int dp[nmax][gmax];
int main()
{
fin>>n>>Gmax;
for(int i=1; i<=n; i++)
fin>>v[i].weight>>v[i].val;
for(int i=1; i<=n; i++)
for(int j=1; j<=Gmax; j++)
if(v[i].weight>j)
dp[i][j]=dp[i-1][j];
else
dp[i][j]=max(dp[i-1][j],dp[i-1][j-v[i].weight]+v[i].val);
fout<<dp[n][Gmax];
}