Thursday, February 25, 2016

LightOJ - 1023 - Discovering Permutations

    1. /****************#####    بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم   #####******************
    2. __________________________________________________________________________
    3. ######################  Ya-Seen Arafat(ACWizard) #########################
    4. ######################        UAP-CSE-33B        #########################
    5. *************************************************************************/
    6. #include <bits/stdc++.h>
    7. using namespace std;
    8.  
    9. int n, m, cn;
    10. bool check[30];
    11. char all[30];
    12.  
    13. void DisPer(int ind){
    14.     if(== ind){
    15.         for(int i = 0; i < n; i++){
    16.             printf("%c", all[i]);
    17.         }
    18.         puts("");
    19.         cn++;
    20.  
    21.         return;
    22.     }
    23.     if(cn >= m)return;
    24.     for(int i = 0; i < n; i++){
    25.         if(!check[i]){
    26.             all[ind] = i+'A';
    27.             check[i] = true;
    28.             DisPer(ind+1);
    29.             check[i] = false;
    30.         }
    31.     }
    32. }
    33.  
    34. int main(){
    35.     int t, cs = 0;
    36.     scanf("%d"&t);
    37.     while(t--){
    38.         cn = 0;
    39.         scanf("%d %d"&n, &m);
    40.         memset(check, falsesizeof(check));
    41.         memset(all, 0sizeof(all));
    42.         printf("Case %d:\n"++cs);
    43.         DisPer(0);
    44.     }
    45.     return 0;
    46. }

No comments:

Post a Comment