Dp on Shifting rooms
450

Thank you guys for giving your precious time here , I am stuck in this problem .
This problem was given to me in previous Exam so it doesnt have a public link.
Any releated pattern problem or same model problem could also help.
No need of code just the procedure is enough.

You are the private owner of two shops. The 1st shop contains N
different goods and all the goods are distinguishiable from one another.

You want to move all the goods from the first shop to the second shop.
The goods can either weigh 100 grams or 300 grams .You can carry at
max K grams of goods at a time.

Also, while moving from one shop to another, you always have to carry
some goods with you, that is, never move empty handed. In case you
move from the second shop to the first shop, then also you should
carry at least one good.

Your task is to find the number of different ways can you move all the
goods from the first shop to the second shop if you take the minimum
possible number of steps. It might be possible that there is no way to move the
goods from me first shop to the second shop. in that case, output - 1.
Note: 1 step is defined as moving from one shop to another

Input Format
1st line contains an integer N, No. of goods
next line integer K, denoting maximum weight u can carry at a time
Each line i of the N subsequent lines (where 0<=i<N) contains an integer denoting the weights of the goods.

Constraints
1<=N<=50
1<=K<=15000
100<=array[i]<=300

Sample Input 1
1
100
100

output:
1

explain:
Only 1 good. So you can move it directly from shop 1 to shop 2.

Sample Input 2:

3
300
100
100
300

output 2

explain:
frist carry both 100,100 to shop 2 while coming take any one of the block ...
since we have the choice to either bring good 1 or good 2 so total 2 ways

Sample Input 3
3
300
300
300
100

output -1

explain :
No possible way to shift all the goods

Comments (1)