Njoj 1251 zlly long a bun face

Source: Internet
Author: User

Njoj 1251 zlly long a bun face

Test instructions
Zlly a bun face, he particularly like to eat sweets, now he has a number of sweets, each candy has a taste value, each kind of candy has countless. Then Lou children's shoes are also very fond of sweets, his taste is particularly extensive, he likes a variety of taste values, he asked zlly with the existing taste value to spell out the new taste value. Now, Lou children's shoes want to know that he can not eat the most taste value is how much? Can you do him a favor?
For example, now zlly has 3,6,10 three kinds of sweets on hand, he can't spell the taste value of 1, 2, 4, 5, 7 ... 17 of sweets, so the result is 17.
In addition, the number of sweets <=10, the taste value of each candy <=265, can guarantee the maximum result of not more than 2,000,000,000. If both can be spelled out or the maximum value does not exist, output 0.

Ideas:
In fact, 2*1e9 is false,
GCD (A1,..., an)!=1, no solution,
GCD (A1,..., an) ==1, there is a solution, the upper bound of the solution is Max (Ai*aj), will not be proven,
So violence can.

/*njoj 1251 zlly Long a bun face test instructions: zlly long a bun face, he particularly like to eat sweets, now he has a number of sweets, each candy has a taste value, each kind of candy has countless many. Then Lou children's shoes are also very fond of sweets, his taste is particularly extensive, he likes a variety of taste values, he asked zlly with the existing taste value to spell out the new taste value. Now, Lou children's shoes want to know that he can not eat the most taste value is how much?  Can you do him a favor? For example, now zlly has 3,6,10 three kinds of sweets on hand, he can't spell the taste value of 1, 2, 4, 5, 7 ...  17 of sweets, so the result is 17. In addition, the number of sweets <=10, the taste value of each candy <=265, can guarantee the maximum result of not more than 2,000,000,000.  If both can be spelled out or the maximum value does not exist, output 0. Idea: In fact, 2*1e9 is virtual, gcd (A1,..., an)!=1, no Solution, GCD (A1,..., an) ==1, there is a solution, the upper bound of the solution is Max (Ai*aj), will not be proven, so violence can be. * * #include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int n=15;const int max_n=1000005;int a[n];bool arr[max_n];void Gao (int N) {memset (arr,0,sizeof (arr)); int Gcd=a [0];for (int i=1;i<n;++i) {GCD=__GCD (gcd,a[i]);} if (gcd!=1) {puts ("0"); return;} int _min=300;for (int i=0;i<n;++i) _min=min (a[i],_min); int cnt=0;int ans;arr[0]=1;for (int i=1;i<max_n;++i) {for ( int j=0;j<n;++j) {if (a[j]>i) continue;if (Arr[i-a[j]]) {arr[i]=1;break;}} if (Arr[i]) ++cnt;else cnt=0;if (cnt==_min) {ans=i-_min;break;}} printf ("%d\n", ans);} int main (){int N;while (scanf ("%d", &n)!=eof) {for (int i=0;i<n;++i) {scanf ("%d", &a[i]);} Gao (n);} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Njoj 1251 zlly long a bun face

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.