Advertisement
cmiN

triti2

Apr 9th, 2011
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. // 45% max
  2. #include <fstream>
  3. #include <cstdlib>
  4. #define ifname "triti2.in"
  5. #define ofname "triti2.out"
  6.  
  7. using namespace std;
  8. fstream fin, fout;
  9. unsigned int k;
  10. unsigned long long n, nr;
  11. char mata[1001], chrset[] = "012";
  12.  
  13. void fuck()
  14. {
  15.     fout.close();
  16. }
  17.  
  18. void init()
  19. {
  20.     fin.open(ifname, ios::in);
  21.     fout.open(ofname, ios::out);
  22.     fin >> k >> n;
  23.     fin.close();
  24.     atexit(fuck);
  25. }
  26.  
  27. void brut_coaie(unsigned int poz)
  28. {
  29.     if (poz == k) {
  30.         nr++;
  31.         if (nr == n) {
  32.             mata[poz] = '\0';
  33.             fout << mata;
  34.             exit(0);
  35.         }
  36.     } else {
  37.         for (unsigned int i = 0; chrset[i]; i++) {
  38.             int res = mata[poz - 1] - chrset[i];
  39.             if (res == 1 || res == -1) {
  40.                 mata[poz] = chrset[i];
  41.                 brut_coaie(poz + 1);
  42.             }
  43.         }
  44.     }
  45. }
  46.  
  47. int main()
  48. {
  49.     init();
  50.     mata[0] = '1';
  51.     brut_coaie(1);
  52.     mata[0] = '2';
  53.     brut_coaie(1);
  54.     fout << -1;
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement