fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int a[100000], b[10000], n,m , dem=0;
  4. vector <int> aa[100];
  5. int ck(int b[])
  6. {
  7. int tong=0;
  8. for(int i=1;i<=n;i++)
  9. {
  10. if(b[i]==1) tong += a[i-1];
  11. }
  12. if(tong ==m) return 1;
  13. return 0;
  14. }
  15.  
  16.  
  17. void out()
  18. {
  19. if(ck(b))
  20. {
  21. for(int i=1;i<=n;i++) if(b[i]==1) aa[dem].push_back(a[i-1]);
  22. dem++;
  23. }
  24. }
  25. void bk(int i)
  26. {
  27. for(int j=0;j<=1;j++)
  28. {
  29. b[i]= j;
  30. if(i==n) out();
  31. else bk(i+1);
  32. }
  33. }
  34. int main()
  35. {
  36. cin>> n>> m;
  37. for(int i=0;i<n;i++) cin>> a[i];
  38. sort(a,a+n);
  39. bk(1);
  40. for(int i=dem-1;i>=0;i--)
  41. {
  42. for(int j=0;j<aa[i].size();j++) cout<< aa[i][j];
  43. cout<< endl;
  44. }
  45. }
Success #stdin #stdout 0.01s 5536KB
stdin
8  53
15  22  14  26  32  9  16  8
stdout
891422
8141516
151622