15,843,727 members
See more: (untagged)
Hello,

I have a problem that I can't solve. It's like a snake moving from the top to the pyramid to the bottom and eat the best score.

3
7 4
2 4 6
8 5 9 3

3+7+4+9=23

But I can't find the last conditions that oblige to choose number adjacents instead of the maximum of the line.

Thanks for helping me !

What I have tried:

```CODE: SELECT ALL
int n = ...;
range rows = 1..n;
int c[rows][rows] = ...;
dvar boolean x[rows][rows];

maximize

sum (i in rows, j in rows) c[i][j]*x[i][j] ;

subject to {
forall(i in rows)
sum(j in rows) x[i][j]==1;
}```
Posted
Updated 25-Nov-17 8:50am
George Jonsson 25-Nov-17 10:54am
Can you elaborate a little bit more about the problem you are trying to solve, as it is not crystal clear.
Shouldn't it be "3+7+6+9=25", if you want the highest score in each row?
Member 13540856 25-Nov-17 12:48pm
No because you only reach adjacents. So in the third line, you can only reach 2 or 4...

Solution 1

Quote:
It's like a snake moving from the top to the pyramid to the bottom and eat the best score.

You have no magic way to know that an answer is the best or not.
It is a brut force attack.
To know that an answer is best score, you need to check all other answers.
You have to build an algorithm that will check every single solution.

[Update]
Quote:
This is in dynamic programmation... But i search for a constraint to avoid to always take the best score and only take adjacent best scores.

As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.

v2
Member 13540856 25-Nov-17 12:50pm
This is in dynamic programmation... But i search for a constraint to avoid to always take the best score and only take adjacent best scores.
Patrice T 25-Nov-17 12:57pm
'linear programming' and 'dynamic programmation' are 2 different things
Member 13540856 25-Nov-17 13:55pm
Ah bon comme si je ne savais pas !
Patrice T 25-Nov-17 14:02pm
Dans le titre c'est une chose et dans le commentaire, c'est autrechose. Il faut choisir le sujet de la question au départ.
Paece que le problème est que la programmation lin"aire est sams repprt avec la problème à résoudre.
Patrice T 25-Nov-17 14:06pm
Et comment on devine puisque ti donnes le mauvais renseignement?

Solution 2

Could someone delete this post ?