Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- import java.io.*;
- public class Mars {
- public static void (String[] args) {
- int n,i,j;
- boolean a;
- n = in.nextInt();
- boolean [][] array = new boolean[n][n];
- boolean [] connect = new boolean[n];
- int [] result = new int[n];
- int [] temp = new int[n];
- int first,last;
- Scanner sc = new Scanner(System.in);
- String s;
- for (i=0;i<n;i++) {
- s = sc.nextLine();
- char [] myCharArray = s.toCharArray ();
- for (j=0;j<n;j++) {
- if (myCharArray[j]=='+') array[i][j] = false;
- else array[i][j] = true;
- }
- }
- a = res(-1,n);
- }
- if (a || (last < n+1)) {
- if (last < first) {
- int[] result = (int[])tmp.clone();
- first=last;
- }
- for (int i=0; i <= first; i++)
- System.out.println(result[i]+" ");
- }
- else System.out.println("No solution");
- public boolean res(int a, int n) {
- for (i=a+1;i<n;i++) {
- if (check_con(i,first) {
- first++;
- result[first] = i;
- connect[i]=true;
- if (res(i,n))
- return true;
- first--;
- connect[i]=false;
- }
- }
- if (check(n)) {
- int[] tmp = (int[])result.clone();
- if (last > first) last = first;
- }
- if (first == n/2 - 1) {
- if (check(n))
- return true
- }
- return false;
- }
- public boolean check_con(int a, int first) {
- int i;
- for (i=0;i<=first;i++) {
- if (!arry[a][result[i]-1])
- return false;
- }
- return true;
- }
- public boolean check(int n) {
- int i,j;
- for (i= 0;i<n-1;i++) {
- if (connect[i]) {
- for (j=i+1;j<n;j++)
- if (!is_connect[j] && !array[i][j])
- return false;
- }
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement