Pagini recente » Cod sursa (job #1248385) | Cod sursa (job #1044863) | Cod sursa (job #303877) | Cod sursa (job #3038522) | Cod sursa (job #3328527)
/******************************************************************************
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;
long long 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]=dp[i-1][j];
}
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;
}