Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. bool PipelinePossible(const int x, const int n, int len[], int count[])
  2. {
  3.     int i;
  4.     bool result = false;
  5.    
  6.     if (x == 0) /* Distance successfully bridged */
  7.     {
  8.         return true;
  9.     }
  10.     else
  11.     {
  12.         for (i = 0; i < n; i++)
  13.         {
  14.             if (len[i] <= x && count[i] > 0) /* Pipe usable and still enough there */
  15.             {
  16.                 count[i]--; /* Use the pipe */
  17.                 /*printf("%d ", len[i]);*/
  18.                 if(PipelinePossible(x - len[i], n, len, count)) /* Try to bridge rest of distance */
  19.                 {
  20.                     result = true;
  21.                 }
  22.                 else
  23.                 {
  24.                     count[i]++; /* Distance couldn't be crossed with the selected pipe, put it back */
  25.                 }
  26.             }
  27.             /*n--;*/
  28.         }
  29.        
  30.         return result;
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement