hello can anyone explain the dynamic programming in a simple way,
I am not able to understand anything in DP
also, in the above DP approach
i only understood that, F§ = min ( F(p-d0),…)+1
so if the highest value is to be repeated more than once, how do you figure it out?
This is my first comment in editorial because i was able to solve this by myself. I dont know if this is the right way to add comments here…but i am posting my solution here…could anyone please suggest the time complexity of this
import math
for i in range(int(input())):
p=int(input())
menus=0
while(p>0):
logValue=int(math.floor(math.log(p,2)))
if(logValue>11):
logValue=logValue=11
p=p-2**logValue
menus+=1
print(menus)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t–)
{
ll p;
cin>>p;
ll x = pow(2,11);
int count = 0;
for (int i = x ; i >=1 ; i=i/2)
{
/* code */
while(i <= p && p>=0){
p-=i;
count++;
}
if (p<0)
break;
}
cout<<count<<endl;
}
return 0;
}
Hi! can someone plez help me with this code, I m not able to identify the error
tc =int(input())
for i in range(tc):
n = int(input())
k=0
for i in range(11,-1,-1):
if 2**(i)<n:
n = n - 2**(i)
k=k+1
if 2**(i) == n:
k=k+1
break
print(k)
Hey I am a newbie coder I have wrote the following code for this problem and I am unable to find out the worst time complexity of my code can some one help me?
#include <iostream>
using namespace std;
int main() {
// your code goes here
int TT ; cin>>TT;
while(TT--)
{
int p ; cin >> p;
int two =2048 , i , rem , dish=0; ;
while(p>0)
{
two =2048;
for( i=11 ; i>=0 ; i--)
{
// cout<<two<<" ";
if(p/two>=1)
{
rem=p/two;
break;
}
two/=2;
}
dish+=rem;
p=p-(two*rem);
}
cout<<dish<<endl;
}
return 0;
}