-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP5863.cpp
56 lines (49 loc) · 1.14 KB
/
P5863.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
#include "header.h"
class Solution {
public:
int countQuadruplets(vector<int>& nums) {
// sort(nums.begin(), nums.end());
answer = 0;
dfs(nums, 0, 0);
return answer;
}
int answer;
int a[4];
void dfs(vector<int> &nums, int depth, int i0)
{
if (depth>=4)
{
if (a[0]+a[1]+a[2] == a[3])
answer++;
return;
}
for (int i=i0; i<nums.size(); i++)
{
a[depth] = nums[i];
dfs(nums, depth+1, i+1);
// if (depth==0)
// dfs(nums, depth+1, i+1);
// else if (depth>0 && a[depth]>a[depth-1])
// dfs(nums, depth+1, i+1);
}
}
};
int main()
{
Solution sol;
vector<int> inp;
int r;
inp = {1,2,3,6};
r = sol.countQuadruplets(inp);
cout << r << endl;
inp = {3,3,6,4,5};
r = sol.countQuadruplets(inp);
cout << r << endl;
inp = {1,1,1,3,5};
r = sol.countQuadruplets(inp);
cout << r << endl;
inp = {28,8,49,85,37,90,20,8};
r = sol.countQuadruplets(inp);
cout << r << endl;
return 0;
}