#include #include #include using namespace std; long*** validPathCount; int pathCount; int maxDown; int maxRight; int maxDStreak; int maxRStreak; long cache_IPMDPC; long cache_IPMRPC; long cache_IMSTRK; long intpow(int base, int power) { if (power==0) return 1; return base * intpow(base, power-1); } long convertedCoordinate(long* inCoord, long base) { int a; int result = 0; for (a=0;a longest) longest = xCoord[a] + yCoord[a]; //Now be certain that all paths of this length are at least properly oriented. lastx = 0; result = -1; for (a=0;a0, I mean that one less must exist in that direction. //For a number=0, it must have come from the other direction with *any* length. //START HERE------------------------------------------------------ if (result == -1) { result = 0; //I think I only need to consider *any* longest staircase. The recursion will take care of the rest. //I know this is theoretically bad style--but it's FAST style. for (a=0;a maxDStreak) { selectedstreaks[a] = selectedstreaks[a] - 1; result = getPathCount(xCoord, yCoord, false, selectedstreaks); selectedstreaks[a] = selectedstreaks[a] + 1; } else { //If the desired length is unspecified in this dimension then find valid ones from the left if (maxRStreak>0) { streak = selectedstreaks[a]; selectedstreaks[a] = 1 + maxDStreak + maxRStreak - 1; result += getPathCount(xCoord, yCoord, false, selectedstreaks); selectedstreaks[a] = streak; } } xCoord[a] = lxc; yCoord[a] = yCoord[a] - 1; //Find valid paths for the one to the left shorter than the desired length. if (selectedstreaks[a] <= maxDStreak) { selectedstreaks[a] = selectedstreaks[a] - 1; result += getPathCount(xCoord, yCoord, false, selectedstreaks); selectedstreaks[a] = selectedstreaks[a] + 1; } else { //If the desired length is unspecified in this dimension then find valid ones from the top if (maxDStreak>0) { streak = selectedstreaks[a]; selectedstreaks[a] = maxDStreak-1; result += getPathCount(xCoord, yCoord, false, selectedstreaks); selectedstreaks[a] = streak; } } yCoord[a] = lyc; break; } } } //Memoize now validPathCount[convertedCoordinate(yCoord, maxRight)][convertedCoordinate(xCoord, maxDown)][convertedCoordinate(selectedstreaks, 2 + maxDStreak + maxRStreak)] = result; } return validPathCount[convertedCoordinate(yCoord, maxRight)][convertedCoordinate(xCoord, maxDown)][convertedCoordinate(selectedstreaks, 2 + maxDStreak + maxRStreak)]; } void main() { long a; long b; long c; long tx; long ty; long result; long cache_IPMDPC; long cache_IPMRPC; long cache_IMSTRK; long quit; long* xCoords; long* yCoords; //Get local parameters printf("Number of paths? "); scanf("%d", &pathCount); printf("Height? "); scanf("%d", &maxDown); printf("Width? "); scanf("%d", &maxRight); //printf("Keep within distance of leftmost (-1 to not specify)? "); printf("Max down streak?"); scanf("%d", &maxDStreak); printf("Max right streak?"); scanf("%d", &maxRStreak); //printf("Max looparound (Y/N)? "); //Report variables (for text output) printf("\n\n"); printf("Variable Report:\n"); printf("Path Count : %d\n", pathCount); printf("Height : %d\n", maxDown); printf("Width : %d\n", maxRight); printf("Down streak : %d\n", maxDStreak); printf("Right streak: %d\n", maxRStreak); printf("\n"); //Allocate memory. I'm going to use a base-system to interleave the paths. //These cache variables will reduce the number of times I must call this function. //Cache these powers. cache_IPMDPC = intpow(maxDown, pathCount); cache_IPMRPC = intpow(maxRight, pathCount); cache_IMSTRK = intpow(2 + maxDStreak + maxRStreak, pathCount); validPathCount = new long**[cache_IPMDPC]; for (a=0;a