Hdu 1171 Big Event in HDU (primary function)

Source: Internet
Author: User

The idea of converting to a primary function is to arrange and combine the devices, create all possible combinations, and search for the total value, as long as the first one is found, using total-I is the two values closest to each other .. So the output is total-I, I. This eliminates the need to worry that the total value is an odd number. The generation function of the primary function can be written in seconds.

[Csharp]
# Include "stdio. h"
# Include "stdlib. h"
# Include "string. h"
Struct node
{
Int v, m, sum;
} Aa [1, 250008];
Int c1 [250008], c2 [250008];
Int main ()
{
Int n, I, j, k, tal;
While (scanf ("% d", & n )! = EOF)
{
If (n <0) break;
Tal = 0;
Memset (c1, 0, sizeof (c1 ));
Memset (c2, 0, sizeof (c2 ));
For (I = 1; I <= n; I ++)
{
Scanf ("% d", & aa [I]. v, & aa [I]. m );
Aa [I]. sum = aa [I]. m * aa [I]. v;
Tal + = aa [I]. sum;
}
C1 [0] = 1;
For (I = aa [1]. v; I <= aa [1]. sum; I + = aa [1]. v)
C1 [I] = 1;
For (I = 2; I <= n; I ++)
{
For (j = 0; j <= tal; j ++)
{
For (k = 0; k + j <= tal & k <= aa [I]. sum; k + = aa [I]. v)
C2 [j + k] + = c1 [j];
}
For (j = 0; j <= tal; j ++)
{
C1 [j] = c2 [j];
C2 [j] = 0;
}
}
For (I = tal/2; I> = 0; I --)
{
If (c1 [I]! = 0) www.2cto.com
{
Printf ("% d \ n", tal-I, I); break;
}
}
}
Return 0;
}


Author: yyf572132811

Related Article

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.