Esempio n. 1
0
 public void Process(int value, ref Int64 total, int remainder, Stack2 state)
 {
     if (remainder != 0)
     {
         if (parent == null)
         {
             if (remainder > 0)
             {
                 if (remainder % Head == 0)
                 {
                     var tc = remainder / Head + state.Sum();
                     if (tc % 2 == 0)
                     {
                         state.Push(remainder / Head);
                         total += new ShareCoinsEvenly(100).WaysToShare(state);
                         state.Pop();
                     }
                 }
             }
         }
         else
         {
             if (SupportsCache())
             {
                 if (cache[remainder] == null)
                 {
                     cache[remainder] = new int[maxValue];
                 }
                 cache[remainder][state.Sum()]++;
             }
             else
             {
                 for (int i = 1; i <= remainder / Head; i++)
                 {
                     state.Push(i);
                     parent.Process(value, ref total, remainder - i * Head, state);
                     state.Pop();
                 }
             }
         }
     }
 }