TSHIRTS - Editorial

Can you please provide some corner test cases. I am getting WA.

2 Likes

How will u have a number with 100 bits??
Are doing it using array, then you can’t perform bitwise operators directly??

1 Like

What if a person doesn’t have that TSHIRT ?

1 Like

The pseudo code accesses dp[mask][tid].
dp has size dp[1<<N][N] where N<11 but tid < 101. Here tid can clearly go outside the limit of the array.
In the actual code you have created array dp[1025][109]

12 Likes

Shouldn’t the expression in line 4 be -

if mask==(2**N)-1:
5 Likes

Also, the dp[][] array should be -

const int K=101;
dp[1<<N][K];

because clearly, we need the TSHIRT no. as the second index, not the user no.

2 Likes

good tutorial :smiley: … helped a lot

1 Like

I think the complexity will be O( 2^N * K * N ) .
Morover, if someone wants to see a backward implementation of this problem, can check my submission .
Also, One can check a very similar problem ASSIGN on spoj.
This problem + ASSIGN on spoj gives you two or more ways of solving this problem.

In general when we need a set we can have options !! That is a very beautiful thing! One should learn that rather learn should feel that !!

dTD9nL - Online C++ Compiler & Debugging Tool - Ideone.com Can someone tell me where im going wrong ?

This site might be useful Bitmasking and Dynamic Programming | Set 1 (Count ways to assign unique cap to every person) - GeeksforGeeks

1 Like

in the solution if (mask == p) then 111 is returned and if not 011 is returned where p is all set mask . Can somebody tell me why?

Because there no mention about it in the pseudo code

The number just needs 10 bits for the number of people. The tee shirt numbers are not part of the bitmask.

1 Like

Then don’t recurse. The code isn’t present, but the idea is represented as a comment.

1 Like

can any one tell me bottom up approach to this problem. it would be great help.

can anyone tell me bottom up approach to this problem. i m not able to figure out how to define state in this problem.

He is definately oing 2 have a shirt read the question carefully,it says each person has atleast 1 shirt

How to do it in a bottom-up fashion, anybody has any idea?
@l_returns @anon55659401 @ssjgz

I won’t be active on discuss for this week :slight_smile:
@l_returns and @ssjgz might surely help :wink:

2 Likes

Here is my attempt to explain the approach to an exactly similar problem
Tshirt Codechef

Can pls someone tell how to take the input.Like in the first case,how would we know if a person has 2 or 3 tshirts.How do i know that the next tshirt is for another guy.