1251-zlly has a steamed stuffed bun face

Source: Internet
Author: User
1251-zlly has a steamed stuffed bun face
    • Time limit:1000MS
    • Memory limit:65535KB
Descriptionzlly has a steamed stuffed bun face, And he especially likes to eat candy. Now he has several types of candy on his hand. Each type of candy has a taste value, and there are countless types of candy. Then, Lou's shoes also like candy very much. He has a wide variety of tastes. He asked zlly to use the existing taste values to create new taste values. Now, Lou Tong's shoes want to know the maximum taste he cannot eat? Can you help him?
For example, zlly has three types of candy on hand: 3, 6, and 10. It cannot spell out the values of 1, 2, 4, 5, and 7... 17 candy, so the result is 17.
In addition, the number of different types of candy <= 10, and the taste value of each type of candy <= 265 can ensure that the maximum result is no more than 2,000,000,000. If both can be spelled out or the maximum value does not exist, the output is 0. Inputline 1: Number of Sweets n
Line 2. n + 1: taste of various sweets;
Input files have the maximum number of flavors that cannot be spelled out by caseoutput. sample input
 
33610
Sample output
 
17
Authoradministrator sourcethe first ACM-ICPC Nanjing Invitational Tournament

 

If there are two numbers P, Q, and gcd (Q, P) = 1, the maximum value cannot be expressed as px + Qy (x> = 0, Y> = 0) the number of values is PQ-Q-P (for N> PQ-Q-P, all values can be expressed as px + Qy, while PQ-Q-P, it cannot be expressed as px + Qy ).

PS: http://www.nocow.cn/index.php/USACO/nuggets

 
# Include <cstring> # include <memory> # include <algorithm> # include <cstdio> using namespace STD; # define Max 265*265 bool DP [Max + 1]; int num [11]; int gcd (int A, int B) {if (a <B) Swap (a, B); int temp = B; if (a % B) {temp = A; A = B; B = TEMP % B;} return B;} int main () {int N, I, J, K; while (scanf ("% d", & N )! =-1) {for (I = 1; I <= N; I ++) scanf ("% d", & num [I]); k = num [1]; for (I = 2; I <= N; I ++) k = gcd (K, num [I]); If (K! = 1) {printf ("0 \ n"); continue;} memset (DP, 0, sizeof (DP); DP [0] = true; for (I = 1; I <= max; I ++) {for (j = 1; j <= N; j ++) if (I> = num [J]) DP [I] = DP [I] | DP [I-num [J];} int res = 0; for (I = max; I> = 1; I --) if (! DP [I]) {res = I; break;} printf ("% d \ n", Res);} 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.