Hdu 1709 The Balance (Master function)

Source: Internet
Author: User

/*

Question: Give You A n, which indicates n items. There are n numbers below, which indicates the weight of n items and then weigh them. Each item has only one item, it can be seen that there are several pieces of value that cannot be claimed, and output it, occupying a single row,

When the value is not zero, the output value cannot be called and is separated by spaces...

The value that cannot be claimed includes the residual values except (directly called) and (derived from the difference .. Ps: A bit round...

In fact, it is more convenient to use dp, but to practice the primary function!

*/

[Html]
# Include "stdio. h"
# Include "string. h"
# Deprecision MAX 10008
Int main ()
{
Int a [MAX], c1 [MAX], c2 [MAX], B [MAX];
Int I, j, k, n, sum;
While (scanf ("% d", & n )! = EOF)
{
Sum = 0;
For (I = 0; I <n; I ++)
{
Scanf ("% d", & a [I]);
Sum + = a [I];
}
For (I = 1; I <= sum; I ++)
{
B [I] = 0;
C1 [I] = c2 [I] = 0;
}
For (I = 0; I <= 1; I ++)
C1 [I * a [0] = 1;
For (I = 1; I <n; I ++)
{
For (j = 0; j <= sum; j ++)
{
For (k = 0; k * a [I] + j <= sum & k <= 1; k ++)
C2 [j + k * a [I] + = c1 [j];
}
For (j = 0; j <= sum; j ++)
{
C1 [j] = c2 [j]; c2 [j] = 0;
}
} // Process of the primary function
For (I = sum; I> 0; I --)
{
If (c1 [I])
{
For (j = 1; j <I; j ++)
{
If (c1 [j])
B [I-j] = 1;
}
}
} <Span style = "COLOR: #008000"> // </span> <span style = "COLOR: #008000 "> here we use this method to find the available difference </span>
K = 0;
For (I = 1; I <= sum; I ++)
{
If (! C1 [I] &! B [I]) // store the unclaimed value into c2 ..
C2 [k ++] = I;
}
Printf ("% d \ n", k );
If (k)
{
For (I = 0; I <K-1; I ++)
Printf ("% d", c2 [I]);
Printf ("% d \ n", c2 [I]);
}
}
Return 0;
}


Author: yyf572132811

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.