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. uint k = 100;
  10.  
  11. alias memstep = memoize!(step, 100 * 100 * 200);
  12.  
  13. BigInt step(uint x, uint y, uint k){
  14.  
  15. if (k==0) {
  16. return ((x==x1) && (y==y1)) ? BigInt("1") : BigInt("0");
  17. }
  18. else {
  19. auto up = (y+1 < m) ? memstep(x, y+1, k-1) : BigInt("0");
  20. auto down = (y-1 >= 0) ? memstep(x, y-1, k-1) : BigInt("0");
  21. auto left = (x+1 < n) ? memstep(x+1, y, k-1) : BigInt("0");
  22. auto right = (x-1 >= 0) ? memstep(x-1, y, k-1) : BigInt("0");
  23.  
  24. return up + down + left + right;
  25. }
  26. }
  27.  
  28. void main()
  29. {
  30. step(50, 50, 200).writeln;
  31. }
Success #stdin #stdout 3.87s 3720KB
stdin
Standard input is empty
stdout
3026331761191340503770893373029273844677591368122716618704642247067326254159330908652193057324457123166746681628950720