public class Valuntary {
public static int maxCost = 0;
public static void main(String[] args) {
// TODO Auto-generated method stub
int n = 4;
int input[][] = {{4,1,2,3},{3,1,2,4},{2,1,4,3},{3,1,2,4}};
enumerate(n, input);
System.out.println("Max Cost : "+maxCost);
}
public static void enumerate(int n, int[][] input){
int[] a = new int[n];
enumerate(a, 0, input);
}
public static int enumerate(int[] a, int k, int[][] input){
int cost = 0;
int n = a.length;
if(k == n){
cost = computeCost(a, input);
if(maxCost < cost){
maxCost = cost;
}
}
else{
for(int i=0; i
if(isConsistent(a, k)){
enumerate(a, k+1, input);
}
}
}
return cost;
}
public static boolean isConsistent(int[] a, int n){
for(int i=0; i
return false;
}
return true;
}
public static int computeCost(int[] a, int[][] input){
int n = a.length;
for(int i=0; i
if (a[i] == j)
System.out.print("O ");
else
System.out.print("* ");
}
System.out.println();
}
int cost = 0;
for(int i=0; i
}
System.out.println("Cost : "+cost);
System.out.println();
return cost;
}
}
No comments:
Post a Comment