#include #include #include #include #include #include static char * stringify(unsigned num, unsigned base, unsigned lpad) { static char buf[16]; unsigned i = sizeof buf; assert(sizeof buf > lpad); buf[--i] = 0; while (num && lpad--) { buf[--i] = num % base + '0'; num /= base; } while (lpad--) { // Left pad buf[--i] = '0'; } return buf + i; } int main(void) { char map[256][256]; // Map with [y][x] coordinates int w,h; // Map size int x,y; // Current position int hx,hy; // Trailhead coordinates int max; // Max number of path permutations int i,j; // General indexes char *path; // Current path unsigned result; // for (h=0; fgets(map[h], sizeof map[0], stdin); h++); w = strlen(map[0]) -1; // -1 for '\n' character at the end of the line // max = pow(4, 9); result = 0; for (hy=0; hy=w || y<0 || y>=h || map[y][x] != j+1+'0') { goto skip; } } result++; skip: continue; } } printf("%u\n", result); return 0; }