-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path3496137_TLE.cc
88 lines (82 loc) · 1.05 KB
/
3496137_TLE.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include<iostream>
#include<algorithm>
using namespace std;
#define MAXN 100
int n,i,len,m,sum;
int s[MAXN];
bool used[MAXN];
bool found;
void dfs(int num,int cur,int next)
{
if(num==m)
{
found=true;
return;
}
int i;
for(i=next;i<n;++i)
{
if(!used[i])
{
if(s[i]+cur==len)
{
used[i]=true;
dfs(num+1,0,0);
if(found)
{
return;
}
used[i]=false;
return;
}
else if(s[i]+cur<len)
{
used[i]=true;
dfs(num,s[i]+cur,i+1);
if(found)
{
return;
}
used[i]=false;
if(cur==0)
{
return;
}
while(i<n-1 && s[i]==s[i+1]) ++i;
}
else
{
return;
}
}
}
}
int main()
{
//freopen("d:/in.txt","r",stdin);
while(cin>>n&&n!=0)
{
sum=0;
for(i=0;i<n;++i)
{
cin>>s[i];
sum+=s[i];
}
sort(s,s+n);
found=false;
memset(used,false,sizeof(used));
for(len=s[n-1];!found&&len<=sum;++len)
{
if(len!=0&&sum%len==0)
{
m=sum/len;
dfs(0,0,0);
if(found)
{
cout<<len<<endl;
}
}
}
}
return 0;
}