forked from sherxon/AlgoDS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaxiforProgrammers2005.java
More file actions
33 lines (31 loc) · 937 Bytes
/
TaxiforProgrammers2005.java
File metadata and controls
33 lines (31 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package timus;
import java.util.Scanner;
/**
* Created by sherxon on 12/6/16.
*/
public class TaxiforProgrammers2005 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int [][] a=new int[6][6];
for (int i = 1; i <=5 ; i++)
for (int j = 1; j <=5 ; j++)
a[i][j]=in.nextInt();
int[][] perm={{1,2,3,4,5},{1,3,2,4,5}, {1,3,4,2,5},{1,4,3,2,5}};
int max=Integer.MAX_VALUE;
int [] cit=null;
for (int i = 0; i < perm.length; i++) {
int sum=0;
for (int j = 0; j <perm[i].length-1 ; j++) {
sum+=a[perm[i][j]][perm[i][j+1]];
}
if(sum<max){
max=sum;
cit=perm[i];
}
}
System.out.println(max);
for (int i = 0; i < cit.length; i++) {
System.out.print(cit[i] + " ");
}
}
}