Hdu_1709 the balence (generation function)

Source: Internet
Author: User
  /*  Use a weight scale to calculate the weight. The weight value can be negative Based on the right code of the left object. Because the maximum weight is one,
Therefore, you are not allowed to use k in a general template as a heavy loop. The number of de-weights is 0, and the number of values is 1. Open
I thought wrong when I first took the negative weight. Wa has been used several times... T_t */

// My code:

# Include <iostream>
# Include <cstdio>
# Include <cstring>

Using Namespace STD;

Const Int N =10007 ;

Int C1 [N], C2 [N];
Int Val [ 107 ];

Int Main (){
// Freopen ("data. In", "r", stdin );

Int N, S, I, j, TMP, CNT;
While (~ Scanf ( " % D " , & N )){
Memset (C1, 0 , Sizeof (C1 ));
Memset (C2, 0 , Sizeof (C2 ));
Memset (Val, 0 , Sizeof (VAL ));

For (S = 0 , I = 1 ; I <= N; ++ I ){
Scanf (" % D " , & Val [I]);
S + = Val [I];
}
C1 [ 0 ] = 1 ; C1 [Val [ 1 ] = 1 ;
For (I = 2 ; I <= N; ++ I ){
For (J = 0 ; J + val [I] <= s; ++ J ){
If (C1 [J]! = 0 ){
C2 [J] + = c1 [J];
C2 [J + val [I] + = c1 [J];
TMP = J-Val [I]; // Wa several times...
TMP = TMP> 0 ? TMP :- 1 * TMP;
C2 [TMP] + = c1 [J];
}
}
For (J = 0 ; J <= s; ++ J ){
C1 [J] = c2 [J]; c2 [J] = 0 ;
}
}
For (CNT = 0 , I = 0 ; I <= s; ++ I ){
If (! C1 [I]) CNT ++;
}
Printf ( " % D \ n " , CNT );
For (J =0 , I = 0 ; I <= S & J <= CNT; ++ I ){
If (! C1 [I]) {
Printf ( " % D " , I); ++ J;
If (J = CNT) putchar ( ' \ N ' );
Else Putchar ( ' ' );
}
}
}
Return 0 ;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.