v 0. Pasted by slipstak2 as cpp at 2012-03-12 20:12:06 MSK and set expiration to never.

Paste will expire never.

  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int n,m;
  8. string letters = "ABCDEFG";
  9. vector<bool> usd;
  10. string res;
  11. void placement_lex(int pos) {
  12.     if (pos == m) {
  13.         printf("%s\n", res.c_str());
  14.         return;
  15.     }
  16.     for (int i=0;i<n;++i) {
  17.         if (!usd[i]) {
  18.             usd[i] = true;
  19.             res[pos] = letters[i];
  20.             placement_lex(pos+1);
  21.             res[pos] = ' '; // debug only
  22.             usd[i] = false;
  23.         }
  24.     }
  25. }
  26. int main() {
  27.     freopen("input.txt","r",stdin);
  28.     freopen("output.txt","w",stdout);
  29.     cin>>n>>m;
  30.     usd.resize(n);
  31.     res.resize(m,' ');
  32.     placement_lex(0);
  33. }


Editing is locked.