Click here to Skip to main content
15,843,727 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

I already wrote this :

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
Comments
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...

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.
 
Share this answer
 
v2
Comments
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?
Could someone delete this post ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900