Advertisement
anhkiet2507

Untitled

Mar 28th, 2022
1,036
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define MAX 100
  3. using namespace std;
  4. int X[MAX], n, k,A[MAX];
  5. vector<vector <string>> res;
  6. using namespace std;
  7. bool Check(vector<int> arr, int k){
  8. int sum = 0;
  9. for(int i = 0; i<k; i++){
  10. sum += arr[i];
  11. }
  12. if(sum%2==0){
  13. return false;
  14. }else{
  15. return true;
  16. }
  17. }
  18. void Init(){
  19. res.clear();
  20. cin >> n;
  21. for(int i = 1; i<=n; i++){
  22. cin >> A[i];
  23. }
  24. sort(A+1, A+n+1, greater<int>());
  25. }
  26. void Result(){
  27. vector<int> tmp1;
  28. tmp1.clear();
  29. for(int i = 1; i <=k; i++){
  30. tmp1.push_back(A[X[i]]);
  31. }
  32. if(Check(tmp1,k)){
  33. vector<string> tmp2;
  34. for(int i = 0; i < k; i++){
  35. tmp2.push_back(to_string(tmp1[i]));
  36. }
  37. res.push_back(tmp2);
  38. }
  39. }
  40. void Try(int i){
  41. for(int j = X[i-1]+1; j<=n-k+i; j++){
  42. X[i] = j;
  43. if(i==k){
  44. Result();
  45. }else{
  46. Try(i+1);
  47. }
  48. }
  49. }
  50. int main(){
  51. int t; cin >> t;
  52. while(t--){
  53. Init();
  54. for(int i = 1; i<=n; i++){
  55. X[0] = 0;
  56. k = i;
  57. Try(1);
  58. }
  59. sort(res.begin(), res.end());
  60. for(int i = 0; i < res.size(); i++){
  61. vector<string> tmp3 = res[i];
  62. for(int j = 0; j < tmp3.size(); j++){
  63. cout << tmp3[j] << " ";
  64. }
  65. cout << endl;
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement