-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathluggage.cpp
86 lines (73 loc) · 1.71 KB
/
luggage.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
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
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
ifstream fin("luggage.in");
ofstream fout("luggage.out");
int main()
{
int totalTest;
fin >> totalTest;
string useless;
getline(fin, useless);
for (int c = 1; c <= totalTest; ++c)
{
string in;
getline(fin, in);
int sizeIN = in.size();
int totalW = 0;
vector<int> a;
string temp;
for (int i = 0; i <= sizeIN - 1; ++i)
{
if (in[i] == ' ')
{
a.push_back(stoi(temp));
totalW += a.back();
temp = "";
}
else
{
temp += in[i];
}
}
a.push_back(stoi(temp));
totalW += a.back();
if (totalW % 2 != 0)
{
fout << "NO\n";
continue;
}
totalW /= 2;
set<int> store;
store.insert(0);
int size0 = a.size();
for (int i = 0; i <= size0 - 1; ++i)
{
set<int> temp = store;
int size1 = store.size();
for (auto it = store.begin(); it != store.end(); ++it)
{
temp.insert(a[i] + *it);
}
store = temp;
}
bool ans = binary_search(store.begin(), store.end(), totalW);
if (ans == true)
{
fout << "YES\n";
}
else
{
fout << "NO\n";
}
}
return 0;
}