标签:方法 nyist 差值 can 不用 nbsp cstring return tab
5 5 8 13 27 14
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> using namespace std ; #define Max(a,b) a>b?a:b int dp[100020] ; int weight[25] ; int main ( ) { int n , i , j ; while ( ~scanf ( "%d" , &n ) ) { memset ( dp , 0 , sizeof(dp) ) ; int sum = 0 ; for ( i = 1 ; i <= n ; i++ ) { scanf ( "%d" , &weight[i] ) ; sum += weight[i] ; } int k = sum / 2 ; for ( i = 1 ; i <= n ; i++ ) { for ( j = k ; j >= weight[i] ; j-- ) { dp[j] = Max ( dp[j] , dp[j-weight[i]] + weight[i] ) ; // if ( dp[j-weight[i]] + weight[i] > dp[j] ) // dp[j] = dp[j-weight[i]] + weight[i] ; } } printf ( "%d\n" , sum - 2 * dp[k] ) ; } return 0 ; }
标签:方法 nyist 差值 can 不用 nbsp cstring return tab
原文地址:http://www.cnblogs.com/ccut-ry/p/7352503.html