phmezymoon 2014-08-12 19:51:43
点我顶贴
收藏
删除
/*先要保证MM足够多,再减少时间,开了两个二维数组,也可以开一个三维数组*/
# include <iostream>
# define min(a,b) a<b?a:b
using namespace std ;
int main ()
{
int dp[101][101] = {0} ;
int t[101][101] = {0} ;
int n , m , r ;
int i , j , k ;
int rmb[101] , rp[101] , time[101] ;
cin>>n ;
for (i = 1 ; i <= n ; i++)
cin>>rmb[i]>>rp[i]>>time[i] ;
cin>>m>>r ;
for (k = 1 ; k <= n ; k++)
for (i = m ; i >= rmb[k] ; i--)
for (j = r ; j >= rp[k] ; j--)
{
if (dp[i][j] < dp[i - rmb[k]][j - rp[k]] + 1)
{
dp[i][j] = dp[i - rmb[k]][j - rp[k]] + 1 ;
t[i][j] = t[i - rmb[k]][j - rp[k]] + time[k] ;
}
else if (dp[i][j] == dp[i - rmb[k]][j - rp[k]] + 1)
t[i][j] = min(t[i][j] ,t[i - rmb[k]][j - rp[k]] + time[k] ) ;
}
cout<<t[m][r]<<endl ;
return 0;
}