I need to find maximum possible sum of numbers in arrays but number must be drawn from a unique array index...just like that:
double maxSum = 0;
double a = {1.0 , 2.0, 3.0};
double b = {4.0 , 5.0, 6.0};
double c = {7.0 , 8.0, 9.0};
sum = a[0] + b[1] + c[2];
// or sum = a[0] + b[2] + c[1]
// or sum = a[1] + b[0] + c[2]
// etc. - how to do that for i arrays and for j numbers in array?
if(sum >=maxSum){
maxSum = sum;
}
this is what I did - but don't have any clue what to do next...
public ArrayList<Double[]> tempArrayCreator() {
ArrayList<Double[]> lists = new ArrayList<Double[]>();
Double[] list1 = { 6.0, 7.0, 6.0 };
Double[] list2 = { 4.5, 6.0, 6.75 };
Double[] list3 = { 6.0, 5.0, 9.0 };
lists.add(list1);
lists.add(list2);
lists.add(list3);
return lists;
}
public double maxPossibleSum(ArrayList<Double[]> lists) {
double result = 0.0;
for (int i = 0; i < lists.size(); i++) {
for (int j = 0; j < lists.get(i).length; j++) {
// ???
}
}
return result;
}
edit. example:
list1 = { 1, 5, 2};
list2 = { 9, 3, 7};
list3 = { 8, 4, 9};
possible solutions:
list1[0] + list2[1] + list3[2] = 13
list1[0] + list2[2] + list3[1] = 12
list1[1] + list2[0] + list3[2] = 23 <-- here it is!
list1[1] + list2[2] + list3[0] = 20
list1[2] + list2[0] + list3[1] = 15
list1[2] + list2[1] + list3[0] = 13