fork download
  1. import std.stdio;
  2. import std.bigint;
  3. import std.functional;
  4.  
  5. uint n = 100;
  6. uint m = 100;
  7. uint x1 = 60;
  8. uint y1 = 60;
  9.  
  10. alias memstep = memoize!(step, 100 * 100 * 200);
  11.  
  12. BigInt step(uint x, uint y, uint k){
  13.  
  14. if (k==0) {
  15. return ((x==x1) && (y==y1)) ? BigInt("1") : BigInt("0");
  16. }
  17. else {
  18. auto up = (y+1 < m) ? memstep(x, y+1, k-1) : BigInt("0");
  19. auto down = (y-1 >= 0) ? memstep(x, y-1, k-1) : BigInt("0");
  20. auto left = (x+1 < n) ? memstep(x+1, y, k-1) : BigInt("0");
  21. auto right = (x-1 >= 0) ? memstep(x-1, y, k-1) : BigInt("0");
  22.  
  23. return up + down + left + right;
  24. }
  25. }
  26.  
  27. void main()
  28. {
  29. step(50, 50, 200).writeln;
  30. }
Success #stdin #stdout 4.02s 3724KB
stdin
Standard input is empty
stdout
3026331761191340503770893373029273844677591368122716618704642247067326254159330908652193057324457123166746681628950720