1 //"n" is the number of kinds. 2 //"m" is the capacity of the bag. 3 //w[]:weight , v[]:value . 4 5 for(int i=1 ; i <= n ; i++) { 6 for(int val=0 ; val<=m ; val++) { 7 if( val >= w[i] ) dp[val] = max( dp[val] , dp[ val-w[i] ]+v[i] ); 8 } 9 }
原文:http://www.cnblogs.com/bruce27/p/4428135.html