-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCTDL_002.cpp
More file actions
44 lines (41 loc) · 708 Bytes
/
Copy pathCTDL_002.cpp
File metadata and controls
44 lines (41 loc) · 708 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> a;
vector<int> b;
vector<vector<int>> ans;
void Try(int sum, int pos)
{
if(sum == k)
{
ans.push_back(b);
}
for(int i = pos; i<n; i++)
{
if(sum + a[i] <=k)
{
b.push_back(a[i]);
Try(sum + a[i], i+1);
b.pop_back();
}
}
}
int main()
{
cin >> n >> k;
a.resize(n);
for(int i = 0; i<n; i++)
{
cin >> a[i];
}
Try(0,0);
for(int i = ans.size()-1; i>=0; i--)
{
for(int j = 0; j<ans[i].size(); j++)
{
cout << ans[i][j] << ' ';
}
cout << endl;
}
cout << ans.size();
}