-
Notifications
You must be signed in to change notification settings - Fork 0
/
thread.cpp
147 lines (100 loc) · 1.81 KB
/
thread.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include<cstdio>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<limits.h>
#include<list>
#include<queue>
#include<bitset>
#include<map>
//#include<unordered_map>
using namespace std;
typedef pair<int, int> ii;
typedef long long int64;
#define Max 3100
#define INF 2000000000
#define TRvi(c, it) \
for(vector<int>::iterator it = c.begin(); it != c.end(); it++)
int N;
vector<int> numbers;
int visited[70000];
//vector<int> sums;
int sums()
{
/*
int count = 0;
queue<ii> q;
//q.push(ii(0, 0));
visited[0] = 1;
count++;
for(int i = 0; i < N; i++)
{
q.push(ii(numbers[i], 1));
visited[numbers[i]] = 1;
count++;
}
while(!q.empty())
{
ii front = q.front();
q.pop();
int sum = front.first;
int index = front.second;
if(index < N)
{
for(int i = 0; i < N; i++)
{
if(!visited[sum+numbers[i]])
{
q.push(ii(sum+numbers[i], index+1));
visited[sum+numbers[i]] = 1;
count++;
}
}
}
}
*/
//int count = 0;
vector<int> sums;
//sums.push_back(0);
//visited[0] = 1;
for(int i = 0; i < N; i++)
{
int size;
if(!visited[numbers[i]])
{
sums.push_back(numbers[i]);
visited[numbers[i]] = 1;
size = sums.size() - 1;
}
else
size = sums.size();
for(int j = 0; j < size; j++)
{
if(!visited[sums[j]+numbers[i]])
{
sums.push_back(sums[j]+numbers[i]);
visited[sums[j]+numbers[i]] = 1;
}
}
}
return sums.size();
}
int main()
{
freopen("thread.in", "r", stdin);
freopen("thread.out", "w", stdout);
int T; scanf("%d", &T);
while(T--) {
scanf("%d", &N);
numbers.clear();
numbers.resize(N);
for(int i = 0; i < N; i++)
scanf("%d", &numbers[i]);
memset(visited, 0, sizeof(visited));
printf("%d\n", sums());
}
return 0;
}