-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphantichso2.cpp
More file actions
51 lines (50 loc) · 1.05 KB
/
phantichso2.cpp
File metadata and controls
51 lines (50 loc) · 1.05 KB
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
//
// created by:DungTD
//
#include <bits/stdc++.h>
#define faster() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define base int (1e9+7)
#define ll long long
using namespace std;
int n, x;
vector <vector <int> > result;
vector <int> res;
void backTrack(int sum, int truoc) {
if (sum < 0) return;
if (sum==0) {
result.push_back(res);
return;
}
for (int i=truoc; i>=1; i--) {
res.push_back(i);
backTrack(sum-i, i);
res.pop_back();
}
}
void solve(){
cin >> n;
result.clear();
backTrack(n, n);
if (result.size() == 0) {
cout << -1 << endl;
} else {
cout << result.size() << endl;
for (int i=0; i<result.size(); i++) {
cout << "(";
for (int j=0; j<result[i].size()-1; j++) {
cout << result[i][j] << " ";
}
cout << result[i].back() << ") ";
}
}
cout << endl;
}
int main(){
faster();
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}