1

I'm trying to devise the most efficient algorithm for a problem, but I'm having some difficulty. If someone could lend a hand, either by proposing an algorithm or classifying the problem so I can do some further research, I would be very appreciative.

The problem is as follows:

There are n (an integer) number of distinct red balls, each of which has its own number, and m number of distinct green balls, each of which has its own corresponding number as well. For example, if n = 3, then there are three red balls named Red Ball 1, Red Ball 2 and Red Ball 3. There are also two boxes in which the balls can be placed.

Before the balls are placed in the boxes however, x number of people make predictions as to which balls will be placed in which box (either box 1 or box 2). Each person gets one prediction and for each prediction they can guess one ball to be in each box. The only condition is that the ball they guess in box 1 cannot be the same color as the ball they guess to be in box 2. An example prediction would be: "I think that Red Ball 2 will be in box 1 and Green Ball 3 will be in box 2"

After everyone has made their predictions, the balls will be placed in the boxes the maximize the number of predictions that are correct.

The code I must write will be prompted with n, m, and x as well as the predictions and then be asked to return the maximum number of predictions that are correct.

Once again, I am looking for either algorithmic help or help to identify the type of problem this is. I currently have a recursive algorithm running on (n^2), but I need something a little more efficient.

Thanks for your help! Cheers, Mates!

user1998665
  • 81
  • 1
  • 5
  • 1
    It may be useful to post the O(N^2) algorithm you have, to give potential answerers a jumping-off point. – Kevin Jan 25 '13 at 16:53
  • You asked this 22 hours ago. You do not have a quadratic algorithm. – tmyklebu Jan 25 '13 at 16:54
  • Does the color restrict placement of the balls, or only the guesses that can be made? In other words, could both boxes end up with a red ball, despite the fact that no one is allowed to guess that way? – twalberg Jan 25 '13 at 17:29
  • @twalberg, yes, the colors in one box can be mixed – user1998665 Jan 26 '13 at 07:03

0 Answers0