• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
  • Carey Brown
  • salvin francis
  • Claude Moore

Distributing k projects to n students  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello! I was wondering if you could help me with something that I am currently stuck on. I could really use some advice in order to complete my assignment.
Here's the task:

Display at the console all possibilities of distributing the k projects to the n students, as well the number of possible solutions, in the below form:

For n=3 (students), k=2 (projects) There are 6 solutions:

1.Tom - “Java Animation”, Jane-“Java Animation”, Kate - “3D Game”
2.Tom - “Java Animation”, Jane - “3D Game”, Kate- “Java Animation”
3.Tom-“Java Animation”,Jane-“3D Game”,Kate-“3D Game”
4.Tom - “3D Game”, Jane - “Java Animation”, Kate –“Java Animation”
5.Tom - “3D Game”, Jane - “Java Animation”, Kate – “3D Game”
6.Tom - “3D Game”, Jane - “3D Game”, Kate –“Java Animation

I've manged to generate the number of solutions,but I don't know if I should use struct in order to display each solution or how I should do it.Here's my code so far:

Posts: 64166
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

There are several questions I think you need to answer before you even think of writing any code:
  • What is your algorithm for distributing projects?
  • How many different combinations are there?
  • Are you using some sort of nCr formula?
  • I think that you will answer many of your other questions if you answer those three first. Why would you want a struct if you can use a class instead?
    Master Rancher
    Posts: 3189
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    The questions are spot on!

    Your 'ways' function has some problems. For instance, if there are N students and just one task, your formula would yield N as result, however, since each of the N students have the same one task, the outcome should be 1.

    A logical requirement would be that the tasks are as evenly distributed as possible (assuming all tasks have the same weight). For instance, if N = 5 and K = 3, then the distribution 1-1-1-2-3 should not be allowed. A simple strategy would be to distribute the K tasks over the first K students, then again the K tasks over the next K students, until all studens have been appointed a task. The number of possibilities would then be:

    (to be disclosed)

    In your example, we have that N = 3, K = 2, and you give 6 possibilities. According to the undisclosed formula above, I would get 4 possibilities (1-2-1, 1-2-2, 2-1-1, 2-1-2). Which of the possibilities that you give do I drop?

    But if the only requirement is that all tasks should be appointed at least once, then the question of how many combinations are possible is really interesting!

    PS: what is factorial(0)?
    It's fun to be me, and still legal in 9 states! Wanna see my tiny ad?
    Create Edit Print & Convert PDF Using Free API with Java
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!