You are not logged in. Please login at www.codechef.com to post your questions!

×

Can someone help me solve this problem?

I came across this problem in a coding test. My solution gave few WA and TLE in some test cases..

You are given X different type of candies represented by 1, 2, 3... X. There are N people each having a list of their favorite candies. You need to find number of ways to distribute these candies such that:

  1. Each person gets exactly one candy from their list of favorite candies.
  2. No two person have same type of candy.

X<= 200, N<=10 and sizeoffavoritelist of each person <= X.

For this problem, I wrote a recursive function, in which for each person it had choice of taking any unvisited candy. But, somehow it gave some WA and TLE. Can someone provide some test cases or correct approach?

asked 18 May '17, 15:38

baap_hu_mae's gravatar image

4★baap_hu_mae
37
accept rate: 0%

edited 18 May '17, 15:39

1

This problem reminds me of a very good problem on codechef itself. https://www.codechef.com/AUG14/problems/TSHIRTS go through the editorial there. This can be done using bitmasking with dp. I hope that u will get a lot help from the editorial itself. Let me know if u still have any doubt.

(18 May '17, 15:54) rachilies4★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×2,167
×345

question asked: 18 May '17, 15:38

question was seen: 268 times

last updated: 18 May '17, 15:55