Guest User

Ég Elska Forritun 1

a guest
Feb 12th, 2011
462
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Numerics; // Þarf að refrencea
  4.  
  5. public class Program
  6. {
  7.     public void main()
  8.         {
  9.         Console.WriteLine(Poss(0, 0));
  10.         Console.ReadLine();
  11.         }
  12.  
  13.         private Dictionary<string, BigInteger> Mem = new Dictionary<string, BigInteger>();
  14.  
  15.         public BigInteger Poss(int x, int y)
  16.         {
  17.             if (x == 100 && y == 100) return BigInteger.One;
  18.  
  19.             string k = x > y ? x.ToString() + "," + y.ToString() : y.ToString() + "," + x.ToString();
  20.             if (Mem.ContainsKey(k)) return Mem[k];
  21.  
  22.             BigInteger n = BigInteger.Zero;
  23.             if (x <= 99 && y <= 99) n += Poss(x + 1, y + 1);
  24.             if (x <= 99) n += Poss(x + 1, y);
  25.             if (y <= 99) n += Poss(x, y + 1);
  26.  
  27.             Mem.Add(k, n);
  28.             return n;
  29.         }
  30. }
RAW Paste Data