Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <cstring>
- #include <iomanip>
- #include <cmath>
- #include <vector>
- #include <string>
- #include <map>
- #include <algorithm>
- #include <deque>
- #include <cstdlib>
- #include <cstdio>
- #include <set>
- using namespace std;
- struct fff {
- int reg1;
- int reg2;
- int k;
- };
- fff from[259] = {};
- int len = 0;
- int reg[277] = {};
- int DFS1(int x) {
- if (x == 1) return 0;
- int reg1 = -1;
- if (from[x].reg1 != 0) {
- bool fnd = false;
- for (int i=0; i<26; i++) {
- if (reg[i] == from[x].reg1) {
- reg1 = i;
- fnd = true;
- break;
- }
- }
- if (!fnd) {
- // if (from[x].reg1 == -1) {
- // cout << ';' << endl; // never printed
- // }
- reg1 = DFS1(from[x].reg1);
- }
- }
- int reg2 = reg[from[x].reg2];
- bool fnd = false;
- for (int i=0; i<26; i++) {
- if (reg[i] == from[x].reg2) {
- reg2 = i;
- fnd = true;
- break;
- }
- }
- if (!fnd)
- reg2 = DFS1(from[x].reg2);
- for (int i=0; i<26; i++) {
- if (reg[i] == 0) {
- reg[i] = x;
- if (reg1 == -1)
- ++len;
- else
- ++len;
- return i;
- }
- }
- return -1;
- }
- int findRes(int start, int reach) {
- vector<int> can;
- can.push_back(0);
- can.push_back(start);
- memset(from, -1, sizeof from);
- from[start].reg1 = 0;
- for (int e=0; e<6; e++) {
- set<int> can2;
- for (int i=0; i<can.size(); i++)
- can2.insert(can[i]);
- for (int x=0; x<can.size(); x++) {
- for (int y=0; y<can.size(); y++) {
- can2.insert(can[x]);
- can2.insert(can[y]);
- for (int k=1; k<=8; k *= 2) {
- if (can[x] + can[y] * k <= 255) {
- if ( from[can[x] + can[y] * k].reg1 == -1) {
- from[can[x] + can[y] * k].reg1 = can[x];
- from[can[x] + can[y] * k].reg2 = can[y];
- from[can[x] + can[y] * k].k = k;
- can2.insert(can[x] + can[y] * k);
- }
- }
- }
- }
- }
- can.clear();
- for (set<int>::iterator it = can2.begin(); it != can2.end(); ++it) {
- can.push_back(*it);
- if (*it == reach) {
- return 1;
- }
- }
- }
- return 0;
- }
- int main() {
- // freopen("input.txt", "r", stdin);
- // freopen("output.txt", "w", stdout);
- int b = 122;
- //cin >> b;
- memset(reg, 0, sizeof reg);
- reg[0] = 1;
- findRes(1,b);
- len = 0;
- DFS1(b);
- printf("%d\n", len );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement