Hello! This is a little task I have below. Can anyone help me? It should be written in Java.

Background

Suppose that you have n^2 football teams, there n is an arbitrarily integer bigger than

or equally with 2.

Divide these teams in groups with n teams in each. IN example below is n=3

and teams are called A, B, C, ... Order between groups and

order between teams within groups plays none role:

A B C D E F G H I

Now let your teams meet within its respective groups. When this is done

you make a new division off teams in groups with n teams in each. There are some terms: Team that earlier has been in same group mustn't

land up in same group again! We can for ex do following division:

A D G B E H C F I

Now we repeat this n+1 times totally, all along with a rule that two teams

that already have been in same group cannot land up in group with each other

again.

After n+1 rounds have each team encountered just n^2-1 teams.

Question is: " Can you find such an arrangement so that each

team encounters each other team exactly once?"

Here is example for n=2 , there a feasible solution would be:

A B C D

A C B D

A D B C

There are several feasible solutions, but the important is just that you have

changed order of rounds and/or order of groups and/or order

of teams within groups comparing with the solution above.

The task.

The task is to write a program that takes in a rate on and

tests if it goes to do a correct arrangement for this.

You can for ex let the program test all feasible

combinations in order to see if they fulfil the term.

For a given n there are two feasible results:

1 Either the program finds a solution. Then the program should print

the found the solution on screen. However it is enough the program finds

one solution, it doesn’t have to look for several.

2 Or the program tests all possibilities and comes to a conclusion that there is no solution. If so, this should be printed out.

The problems with this the task is that for a little bigger n it takes so

long time to test all combinations.

Then can you find and implement some optimisations that do that

the program not acquires testing just all possibilities, for ex through

utilising symmetry. But you should motivate why the optimisation you did were ok and you won't miss any solutions because of them.

The point with the task is to make the program manage the solution

(i.e. come to either cases 1 or cases 2 above) in a reasonable time, there reasonable

time can be maximum a day.