2-ая (что пришло первое на ум):
C++ |
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
| #include <iostream>
#include <math.h>
using namespace std;
int main(){
int n, x, i, j, tmp;
bool a[10001][2];
for(i=0; i<10001; i++)
a[i][0]=false;
a[0][0]=true;
cin>>n>>x;
for(i=0; i<n; i++)
{
if(i%2)
{
for(j=0; j<10001; j++)
a[j][0]=false;
cin>>tmp;
for(j=0; j<10001; j++)
if(a[j][1])
{
a[abs(j-tmp)][0]=true;
a[abs(j+tmp)][0]=true;
}
}
else
{
for(j=0; j<10001; j++)
a[j][1]=false;
cin>>tmp;
for(j=0; j<10001; j++)
if(a[j][0])
{
a[abs(j-tmp)][1]=true;
a[abs(j+tmp)][1]=true;
}
}
}
if(n%2)
{
if(a[abs(x)][1])
cout<<"yes";
else
cout<<"no";
}
else
{
if(a[abs(x)][0])
cout<<"yes";
else
cout<<"no";
}
return 0;
} |
|