Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define MAX 100
- using namespace std;
- int X[MAX], n, k,A[MAX];
- vector<vector <string>> res;
- using namespace std;
- bool Check(vector<int> arr, int k){
- int sum = 0;
- for(int i = 0; i<k; i++){
- sum += arr[i];
- }
- if(sum%2==0){
- return false;
- }else{
- return true;
- }
- }
- void Init(){
- res.clear();
- cin >> n;
- for(int i = 1; i<=n; i++){
- cin >> A[i];
- }
- sort(A+1, A+n+1, greater<int>());
- }
- void Result(){
- vector<int> tmp1;
- tmp1.clear();
- for(int i = 1; i <=k; i++){
- tmp1.push_back(A[X[i]]);
- }
- if(Check(tmp1,k)){
- vector<string> tmp2;
- for(int i = 0; i < k; i++){
- tmp2.push_back(to_string(tmp1[i]));
- }
- res.push_back(tmp2);
- }
- }
- void Try(int i){
- for(int j = X[i-1]+1; j<=n-k+i; j++){
- X[i] = j;
- if(i==k){
- Result();
- }else{
- Try(i+1);
- }
- }
- }
- int main(){
- int t; cin >> t;
- while(t--){
- Init();
- for(int i = 1; i<=n; i++){
- X[0] = 0;
- k = i;
- Try(1);
- }
- sort(res.begin(), res.end());
- for(int i = 0; i < res.size(); i++){
- vector<string> tmp3 = res[i];
- for(int j = 0; j < tmp3.size(); j++){
- cout << tmp3[j] << " ";
- }
- cout << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement