/ *
Problem Description
each item has a certain volume (nonsense), different combinations of goods, into a bag with a certain total volume of battle.
If every member has unlimited items available, some volume is never out of the package.
To try to fill a backpack, High School OIER want to look at the largest volume items can not be put in.
Title ensure a solution, if the solution is limited to ensure that not more than 2,000,000,000
If the solution is infinite, the output 0
the input format of
the first row of an integer n (n <= 10), indicates the number of items in
the second row line 1 to N +: volume of each item (1 <= <= 500)
output format of
an integer ans, represents the largest volume use of these items can not be obtained.
Sample input
. 3
. 3
. 6
10
sample output
17
* /
#include<stdio.h>
#include<string.h>
int gcd(int,int);
int is_wj(int,int[],int*);
int q_zhi(int,int[],int);
void input(int,int[]);
int main(void)
{
int n;
scanf("%d",&n);
int sz[n],min = sz[0];;
input(n,sz);
if(is_wj(n,sz,&min))
{
puts("0");
}
else
{
printf("%d",q_zhi(n,sz,min));
}
return 0;
}
int q_zhi(int n,int sz[],int min)
{
static char jl[500*500] = {0};
jl[0] = 1;
int i,j,sum = 0,max = -1;
for(i = 0;i < 499*500 && sum < min;i++)
{
if(jl[i])
{
for(j = 0;j < n;j++)
{
jl[sz[j]+i] = 1;
}
sum++;
}
else
{
max = i;
sum = 0;
}
}
return max;
}
int gcd(int a,int b)
{
return a%b ? gcd(b%a,a):b;
}
int is_wj(int n,int sz[],int*p_min)
{
int i,tmp = sz[0];
*p_min = sz[0];
for(i = 1;i < n;i++)
{
if(*p_min > sz[i])
{
*p_min = sz[i];
}
tmp = gcd(tmp,sz[i]);
}
return tmp != 1 || *p_min == 1;
}
void input(int n,int sz[])
{
while(n--)
{
scanf("%d",sz++);
}
}