PoliticsProblem code: DPC205 |
All submissions for this problem are available.
Politics
Leaders of N political parties agree to have a conference to resolve a political issue through discussion. However due to animosity between parties and leaders, some of the leaders may dislike sitting next to leaders specified by them. The problem is to determine, if possible, sitting arrangements on the table, so that a leader is not required to sit next to another leader disliked by him/her. Leaders are identified by integers 1,2,..,N. It may be noted that if a leader i dislikes sitting next to another leader j , then the leader j may not necessarily dislike sitting next to leader i . However in such a case i and j cannot sit next to each other because i dislikes j .
An arrangement is represented by a sequence of N integers 1,2, ,N indicating the relative position of each leader. In case of more than one arrangement, the arrangements are to be printed in lexicographic order.
Write a program to print all possible sitting arrangements for the conference.
Input:
The input may contain multiple test cases. The first line of each test case contains the case number c and the total number of leaders N where N will be less than 100. Each of the next N lines contains N 0 s or 1 s. If the value in ith row and jth column contains 1, then the ith leader cannot sit with jth leader. This is true for all I,j=1,2, ,N. The input terminates with a single 0 in the last line.
Output:
For each test case, print the case number c and the total number of possible arrangements k in first line with a single space between them. Each of the next k lines prints an arrangements in lexicographical order separated with a single space.
Sample Input
1 5
11010
01001
00100
10010
01011
2 6
101100
010001
101000
100110
001011
010011
0
Sample Output
1 0
2 2
1 5 2 3 4 6
1 5 2 4 3 6
| Date: | 2010-03-10 |
| Time limit: | 5s |
| Source limit: | 50000 |
| Languages: | C C99 strict C++ 4.0.0-8 C++ 4.3.2 PAS gpc PAS fpc JAVA NICE JAR C# C#2 NEM ST ASM D FORT ADA BASH PERL PYTH RUBY LUA ICON PIKE PHP SCM guile SCM qobi LISP sbcl LISP clisp SCALA HASK ERL CAML CLPS PRLG WSPC BF ICK JS |
Comments

Fetching successful submissions

Please register at
Please register at http://bit.ly/DSPPC2_Register to claim prizes and certificates.
Admin: The aim of this
Admin: The aim of this contest is to promote programming and not to adjudge the best programmers. We request the participants to maintain a Healthy Competition. Any mal-practices if found will lead to Disqualification from the Series. If any such codes have been submitted consider submitting fresh codes.
isn't this a valid solution
isn't this a valid solution for testcase 2
1 6 3 4 2 5
???
isn't this a valid solution
isn't this a valid solution for testcase 2
1 6 3 4 2 5
???
The CodeChef Rankings are not
The CodeChef Rankings are not accepted Directly. Some Mal-Practices have been observed and Strict action would be taken.
Isn't 15324 correct
Isn't 15324 correct combination for first case ?