Pagini recente » Cod sursa (job #541139) | Borderou de evaluare (job #291215) | Cod sursa (job #2540357) | Cod sursa (job #371803) | Cod sursa (job #2239794)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("energii.in") ;
ofstream fout("energii.out") ;
int dp[1005][10005] ;
int e[1005] , c[1005] ;
int main()
{
int i , j , g , w ;
fin >> g >> w ;
for ( i = 1 ; i <= g ; i++ )
{
fin >> e[i] >> c[i] ;
dp[1][e[i]] = c[i] ;
}
for ( i = 2 ; i <= g ; i++ )
{
for ( j = 1 ; j <= w ; j++ )
{
dp[i][j] = dp[i-1][j] ;
if ( j-e[i] >= 0 && dp[i-1][j-e[i]] != 0 )
dp[i][j] = min(dp[i][j],dp[i-1][j-e[i]] + c[i]) ;
}
}
fout << dp[g][w] ;
}