View Code
1 #include2 #include 3 #include 4 #include 5 using namespace std; 6 int main() 7 { 8 int n; 9 while(cin>>n) 10 { 11 int *a=new int[n]; 12 int i,j,sum=0; 13 for(i=0;i >a[i],sum+=a[i]; 14 int total=sum>>1; 15 int *bag=new int[total+2]; 16 memset(bag,0,sizeof(int)*(total+2)); 17 for(i=0;i =a[i];j--) 19 { 20 bag[j]=max(bag[j],bag[j-a[i]]+a[i]);//背包 21 } 22 //cout< <