A company produce product
Need quick help
Hi
you can think recursive solution,
let f(x)= minimum number of days required to produce x products
the
f(x) = min( f(x/2) , f(x) ) +1
( Base condition you can think!)
you can convert this into DP to optimise using the same equation.
I hope this was quick!.
Hit Like if you get it!
Cheers!
Happy Coding.
1 Like
Lol, I already wrote this code, please check it out.
def func(n):
t = n
cnt = 0
i = 0
while t>1:
if t%2 == 1:
cnt = cnt +1
i = i + 1
t= int(t/2)
return (i+cnt)
Seems Correct.
you can compare to this may be:
int fuc(int n)
{
vector dp(n+1);
int i;
for(i=2;i<=n;i++)
if(i%2==1)
dp[i]=dp[i-1]+1;
else
dp[i]=min(dp[i/2],dp[i-1])+1;
return dp[n];
}