I'm having some trouble resolving a problem that I believe needs the use of depth-first-search algorithm.
This problems involves trying to find the biggest value of the path, but every time you walk through the path, you can either go straight or to your left.
Here is a example of a path:
_
|2|_
|2|1|_
|4|9|4|_
|3|2|1|2|
The biggest value in this path would be 2+2+9+2 = 15
Now to the problem:
I've decided that the best way to solve this problem is to make a adjacency list and use a stack with DFS to get the biggest value of the path, but I'm having a hard time figuring out how to create the adjacency list, considering that the program input is:
4 //Number of lines
2 // First line
2 1
4 9 4
3 2 1 2
Here is what I have so far
// Recieve the size of the path
scanf("%d", &nN);
// Get the amount of elements in the list: n!
for( i = 0, nFact = 0 ; i < nN ; i++ )
nFact += nN - i;
// Create list of adjacency
list = malloc( nFat * sizeof( List ) );
// Insert elements
for( i = 0 ; i < nN ; i++ ) {
scanf("%d", list[i].value);
lista[i].color = 0;
lista[i].prox = NULL;
// No idea on how to insert the elements on their specific slot and on their adjacency, as the number keeps increasing for each line
}