-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3602.cpp
57 lines (49 loc) · 963 Bytes
/
3602.cpp
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
#include <iostream>
#include <vector>
using namespace std;
class Road
{
public:
Road(int len): length_(len) {}
bool IsInArea(int point)
{
return (point >= 0) && (point < length_);
}
bool IsValid(int start, const vector<int>& distances,
int beg, int end)
{
if (end - beg == 0)
return IsInArea(start);
return IsValid(start + distances[beg],
distances,
beg + 1,
end)
|| IsValid(start - distances[beg],
distances,
beg + 1,
end);
}
private:
int length_ = 0;
};
int main()
{
int N, M;
cin >> N >> M;
vector<int> Ds;
for (int i = 0, tmp; i != M; ++i)
{
cin >> tmp;
Ds.push_back(tmp);
}
// io done
Road rd(N);
int num_valid = 0;
for (int i = 0; i < N; ++i)
{
if (rd.IsValid(i, Ds, 0, Ds.size()))
++num_valid;
}
cout << num_valid;
return 0;
}