You can also use dynamic programming if the problem is divided into smaller subtasks, for example,
F (x, y) = F (x-1, y) + F (x, y-1)
here F (x, y) is divided into smaller subtasks, so DP can be used
int arr[xmax+1][ymax+1]; //base conditions for(int i=0;i<=xmax;i++) arr[i][0] = 1 for(int j=0;j<=ymax;j++) arr[0][j] = 1; // main equation for(int i=1;i<=xmax;i++) { for(int j=1;j<=ymax;j++) { arr[i][j] = arr[i-1][j] + arr[i][j-1]; } }
As you mentioned, the DP compiler optimizer can be used for this, you just need to write instructions in the compiler, which on a recursive solution checks if it is divided into smaller subtasks, if so, then use DP with a simple loop like above, but the most difficult part is optimization automatically, for example, over DP it needs the O(xmax*ymax) , but can be easily optimized to get a solution in the O(xmax+ymax) space
Solver example: http://www.cs.unipr.it/purrs/
Vikram Bhat
source share