CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • February CookOff
    • February Long Contest
    • January CookOff
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Ranks
    • Tutorials
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » DreamSpark 2 » Politics

Politics

Problem code: DPC205

  • All Submissions

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


  • Submit

Comments

  • Login or Register to post a comment.

Please register at

MSP_bitmesra @ 13 Mar 2010 07:55 PM

Please register at http://bit.ly/DSPPC2_Register to claim prizes and certificates.

Admin: The aim of this

szk @ 14 Mar 2010 12:58 AM

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

jitendra_theta @ 14 Mar 2010 02:33 PM

isn't this a valid solution for testcase 2

1 6 3 4 2 5

???

isn't this a valid solution

jitendra_theta @ 14 Mar 2010 02:35 PM

isn't this a valid solution for testcase 2

1 6 3 4 2 5

???

The CodeChef Rankings are not

MSP_bitmesra @ 15 Mar 2010 02:37 AM

The CodeChef Rankings are not accepted Directly. Some Mal-Practices have been observed and Strict action would be taken.

Isn't 15324 correct

alok @ 18 Mar 2010 07:40 AM

Isn't 15324 correct combination for first case ?

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our judge accepts solutions in over 35+ programming languages. Online programming was never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming competitions that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef and be a guest author on our blog.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com