473,385 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

help to solve this question

1
a set of n people(say a,b,c,d) need to assemble as two different teams in
two different rooms (say r1 and r2) to attend discuss two different
topics. participants are given options to pick the room of their interest,
print all the possible ways in which they can conduct the meetings.(while
printing the output, arrange the possiblities in such a way that no. of
people in r1 is in ascending order, and when the no. of people in r1 are
same, the groups are sorted based on their alphabetical order. note that a
set itself is printed as sorted character list. also assume 2<=n<=26)

sample input:
2

output:
- ab
a b
b a
ab -
Sep 15 '06 #1
3 1481
risby
30
a set of n people(say a,b,c,d) need to assemble as two different teams in
two different rooms (say r1 and r2) to attend discuss two different
topics. participants are given options to pick the room of their interest,
print all the possible ways in which they can conduct the meetings.(while
printing the output, arrange the possiblities in such a way that no. of
people in r1 is in ascending order, and when the no. of people in r1 are
same, the groups are sorted based on their alphabetical order. note that a
set itself is printed as sorted character list. also assume 2<=n<=26)

sample input:
2

output:
- ab
a b
b a
ab -

I don't understand this at all. What does your sample input mean? Is it that there are just two people? If so then a will go to one room and b to another where they will talk to themselves. What do the space and the dash in your output represent?
Sep 15 '06 #2
D_C
293 100+
Encode the problem using a binary string, and also use recursion.
Suppose n = 6. Then have a six digit binary string, modeled by a six entry boolean array. Then 000000 means all six people are in the first room, 111111 means all six are in the second room. For persons A, C, and D to be in the first room, while B, E, F are in the second, is 010011.

It's 51 lines of code. Of course, I could delete four sets of parenthesis and get it down to 43 lines of code.
Expand|Select|Wrap|Line Numbers
  1. Enter number of people: 4
  2. -       abcd
  3. d       abc
  4. c       abd
  5. cd      ab
  6. b       acd
  7. bd      ac
  8. bc      ad
  9. bcd     a
  10. a       bcd
  11. ad      bc
  12. ac      bd
  13. acd     b
  14. ab      cd
  15. abd     c
  16. abc     d
  17. abcd    -
  18. Press any key to continue . . .
Sep 15 '06 #3
D_C
293 100+
Actually, after thinking about it, recursion is not necessary. It's tail end, so it could be converted to a for loop. Then, you could encode the 2^N possibilities by counting from 0 to (2^N - 1).
Sep 15 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: the_proud_family | last post by:
HELP ME PLEASE!! my email is the_proud_family@yahoo.com I can't get the ball to go up right side and then I need it to turn around and keep turning until velocity=0 I have been at it for the ...
3
by: Jay | last post by:
I previously posted this question under Visual Basic newsgroup, but was advised to re-post here. I'm hoping someone can help me solve an issue I'm having with VB.Net and Access 2000. Here's...
15
by: Holly | last post by:
I'm trying to get this page to look the same in Netscape and IE. I have a box that says 'Upcoming Events' on the lower left of the page. It's supposed to have a gray background, but in NS 4.x it...
12
by: Vibhajha | last post by:
Hi friends, My sister is in great problem , she has this exam of C++ and she is stuck up with some questions, if friends like this group provides some help to her, she will be very grateful....
15
by: Alfonso Morra | last post by:
Hi, I have some code from an example, that I want to retrofit into my project. The code from the example has the following line: SharedAppenderPtr myAppender( new...
1
by: Mohammed Mazid | last post by:
Basically I want to store the answer of a single-choice question (where candidate selects one answer) and multiple-choice question (where candidate selects more than one answer). I would like to...
16
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client...
16
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and...
1
by: myemail.an | last post by:
Hi all, I am a novice to Access, and was wondering if I could get some help on a problem I can't solve. I have a database with customer payments, structured like this: customer code type of...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.