Найти оптимизированный путь к расходу через сетку / матрицу в C ++

Я застрял с проблемой и не смог найти много помощи в Интернете. Мне нужно найти минимальную стоимость комбинации чисел из нескольких векторов чисел. Размер вектора же для всех векторов. Например, рассмотрим следующее:

row [0]:  a  b  c  d   
row [1]:  e  f  g  h  
row [2]:  i  j  k  l  

Теперь мне нужно найти комбинацию номеров, принимая один элемент из каждой строки I.E Vector, например: AEI
После этого мне нужно найти три трех комбинации, которые не пересекаются друг с другом, например: BFJ, CGK, DHL. Я рассчитываю стоимость на основе этих четырех комбинаций. Цель состоит в том, чтобы найти комбинацию, которая дает минимальную стоимость. Другая возможная комбинация может быть: AFJ, Bei, CHK, DGL. Если общее количество столбцов D и строки k, общая комбинация возможна d ^ k. Ряды хранятся в виде векторов. Я застрял здесь, я трудно написать алгоритм для вышеуказанного процесса. Я бы очень признателен, если кто-то может помочь.
Спасибо.

// I am still working on the algorithm. I just have the vectors and the cost function.  

//Cost Function  , it also depends on the path chosen
float cost(int a, int b, PATH to_a) {  
float costValue;  
...  
...  
return costValue;  
}  

vector< vector < int > > row;  
//populate row  
...   
...
//Suppose  

//    row [0]:  a  b  c  d   
//    row [1]:  e  f  g  h  
//    row [2]:  i  j  k  l   

// If a is chosen from row[0] and e is chosen from row[1] then,  
float subCost1 = cost(a,e, path_to_a);  

// If i is chosen from row[2] ,  
float subCost2 = cost(e,i,path_to_e);  

// Cost for selecting aei combination is  
float cost1 = subCost1 + subCost2;  

//similarly other three costs need to be calculated by selecting other remaining elements  
//The elements should not intersect with each other eg. combinations aei and bej cannot exist on the same set.  

//Suppose the other combinations chosen are bfj with cost cost2, cgk with cost cost3   and dhl with cost cost4  
float totalCost = cost1 + cost2 + cost3 + cost4;   

//This is the cost got from one combination. All the other possible combinations should be enumerated to get the minimum cost combination. 
13
задан coolcav 12 September 2011 в 20:44
поделиться