Pagini recente » Cod sursa (job #864587) | Cod sursa (job #307361) | Cod sursa (job #1190763) | Cod sursa (job #700406) | Cod sursa (job #3328524)
/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <iostream>
#include <fstream>
using namespace std;
int dp[5001][10001], mat[5001][10001];
int main()
{
ifstream f("rucsac.in");
ofstream g("rucsac.out");
int n,gmax;
f>>n>>gmax;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=2; j++)
{
f>>mat[i][j];
}
}
for(int i=1; i<=n; i++)
{
for(int j=1; j<=gmax; j++)
{
if(mat[i][1]>j)
{
dp[i][j]=0;
}
else
{
dp[i][j]=max(dp[i-1][j-mat[i][1]]+mat[i][2], dp[i-1][j]);
}
}
}
g<<dp[n][gmax];
return 0;
}