Pagini recente » Cod sursa (job #1500005) | Cod sursa (job #850781) | Cod sursa (job #810778) | Cod sursa (job #3131967) | Cod sursa (job #1786308)
#include <iostream>
#include <fstream>
#define gmax 1002
#define wmax 5002
using namespace std;
int dp[gmax][wmax],w[gmax],c[gmax],G,W;
int main()
{
ifstream fin ("energii.in");
ofstream fout("energii.out");
fin>>G>>W;
for(int i=1; i<=G; i++)
fin>>w[i]>>c[i];
for(int i=1; i<=G; i++)
dp[i][0]=1;
for(int i=1; i<=G; i++)
{
for(int j=1; j<=W; j++)
{
if(dp[i][j-w[i]])
{
dp[i][j]=dp[i][j-w[i]]+w[i];
//if(!(j-w[i]))
//dp[i][j]--;
}
else if(dp[i-1][j-w[i]])
{
dp[i][j]=dp[i-1][j-w[i]];
//if(!(j-w[i]))
//dp[i][j]--;
}
}
}
fout<<dp[G][W];
return 0;
}