Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool PipelinePossible(const int x, const int n, int len[], int count[])
- {
- int i;
- bool result = false;
- if (x == 0) /* Distance successfully bridged */
- {
- return true;
- }
- else
- {
- for (i = 0; i < n; i++)
- {
- if (len[i] <= x && count[i] > 0) /* Pipe usable and still enough there */
- {
- count[i]--; /* Use the pipe */
- /*printf("%d ", len[i]);*/
- if(PipelinePossible(x - len[i], n, len, count)) /* Try to bridge rest of distance */
- {
- result = true;
- }
- else
- {
- count[i]++; /* Distance couldn't be crossed with the selected pipe, put it back */
- }
- }
- /*n--;*/
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement