- /****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####******************
- __________________________________________________________________________
- ###################### Ya-Seen Arafat(ACWizard) #########################
- ###################### UAP-CSE-33B #########################
- *************************************************************************/
- #include <bits/stdc++.h>
- using namespace std;
- int n, m, cn;
- bool check[30];
- char all[30];
- void DisPer(int ind){
- if(n == ind){
- for(int i = 0; i < n; i++){
- printf("%c", all[i]);
- }
- puts("");
- cn++;
- return;
- }
- if(cn >= m)return;
- for(int i = 0; i < n; i++){
- if(!check[i]){
- all[ind] = i+'A';
- check[i] = true;
- DisPer(ind+1);
- check[i] = false;
- }
- }
- }
- int main(){
- int t, cs = 0;
- scanf("%d", &t);
- while(t--){
- cn = 0;
- scanf("%d %d", &n, &m);
- memset(check, false, sizeof(check));
- memset(all, 0, sizeof(all));
- printf("Case %d:\n", ++cs);
- DisPer(0);
- }
- return 0;
- }
Thursday, February 25, 2016
LightOJ - 1023 - Discovering Permutations
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment