You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
const int N = 110 ;
int n , m ;
int f [ N ] [ N ] , v [ N ] [ N ] , w [ N ] [ N ] , s [ N ] ;
int main ( ) {
cin > > n > > m ;
for ( int i = 1 ; i < = n ; i + + ) {
cin > > s [ i ] ; // 第i个分组中物品个数
for ( int j = 1 ; j < = s [ i ] ; j + + )
cin > > v [ i ] [ j ] > > w [ i ] [ j ] ; // 第i个分组中物品的体积和价值
}
for ( int i = 1 ; i < = n ; i + + ) // 每组
for ( int j = 0 ; j < = m ; j + + ) { // 每个合法体积
f [ i ] [ j ] = f [ i - 1 ] [ j ] ; // 如果一个都不要, 那么这一组就相当于白费, 给你机会也不中用, 继承于i-1
for ( int k = 1 ; k < = s [ i ] ; k + + ) // 选择第k个
if ( j > = v [ i ] [ k ] )
f [ i ] [ j ] = max ( f [ i ] [ j ] , f [ i - 1 ] [ j - v [ i ] [ k ] ] + w [ i ] [ k ] ) ; // 枚举每一个PK一下大小
}
// 输出打表结果
printf ( " %d " , f [ n ] [ m ] ) ;
return 0 ;
}