Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 45% max
- #include <fstream>
- #include <cstdlib>
- #define ifname "triti2.in"
- #define ofname "triti2.out"
- using namespace std;
- fstream fin, fout;
- unsigned int k;
- unsigned long long n, nr;
- char mata[1001], chrset[] = "012";
- void fuck()
- {
- fout.close();
- }
- void init()
- {
- fin.open(ifname, ios::in);
- fout.open(ofname, ios::out);
- fin >> k >> n;
- fin.close();
- atexit(fuck);
- }
- void brut_coaie(unsigned int poz)
- {
- if (poz == k) {
- nr++;
- if (nr == n) {
- mata[poz] = '\0';
- fout << mata;
- exit(0);
- }
- } else {
- for (unsigned int i = 0; chrset[i]; i++) {
- int res = mata[poz - 1] - chrset[i];
- if (res == 1 || res == -1) {
- mata[poz] = chrset[i];
- brut_coaie(poz + 1);
- }
- }
- }
- }
- int main()
- {
- init();
- mata[0] = '1';
- brut_coaie(1);
- mata[0] = '2';
- brut_coaie(1);
- fout << -1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement