Programming Course - Intermediate Level: Recursion, Backtracking, Pointers, Lists by Gabriel Braharu

Programming Course - Intermediate Level: Recursion, Backtracking, Pointers, Lists by Gabriel Braharu

Author:Gabriel Braharu
Language: eng
Format: azw3
Published: 2017-08-17T07:00:00+00:00


The solution vector has a number of fixed elements ka = 3 because tricolours flag.

WriteSolution()

i integer

For i<-1,ka do

Write m[v[i]]

Write „Enter”

Write the solution vector with ka elements

MainProgram()

i integer

Read n,ka

For i<-1,n do

Read m[i]

Backtracking()

It reads also a vector of natural numbers (or color names) m

C. Find out all the possibilities of arranging n persons on one side of a dining table with ka places with the restriction that two women cannot stand one near another.

Solution: in the main program, we will have read a vector with n elements (names of people-strings) and of course the vector m will be declared global. For the present problem, we note that it preserves all existing conditions of restriction of the permutations (distinct elements in vector), it adds a constraint so cannot sit two women one near another (it is assumed that we can identify the feminine or masculine through the sequence of characters "f" or "m", also it keeps conditions for continuity. In relation to the permutation algorithm, we modify the ValidElement(k), SolutionVector(k), WriteSolution () and main program.

ValidElement(k integer) boolean

i integer

For i<-1,k-1 do

If v[i]=v[k] Then

Return False

For i<-1,k-1 do

If m[v[i]]=m[v[i+1]] and

m[v[i]]=”-f-” Then

Return False



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.