-
Notifications
You must be signed in to change notification settings - Fork 0
/
MAIN72.cpp
49 lines (43 loc) · 908 Bytes
/
MAIN72.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
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define lld long long int
int n,arr[100+1],dp[104][100001];
set <int> s;
int fun(int i,int sum)
{
if(i==n+1)
{
s.insert(sum);
return 0;
}
if(dp[i][sum]!=-1)
return dp[i][sum];
return dp[i][sum]=arr[i]+fun(i+1,sum+arr[i])+fun(i+1,sum);
}
//-4%3=-1
int main() {
// your code goes here
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lld t;
cin>>t;
while(t--)
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>arr[i];
memset(dp,-1,sizeof(dp));
fun(1,0);
int res=0;
for(auto i:s)
{
//cout<<i<<' ';
res+=i;
}
cout<<res<<'\n';
s.clear();
}
}