Can you share your MLE code? What I thought was the problem was variation of unbounded knapsack where the catch is we can take fixed K amount of any item and not infinite number of any item.Correct me if I am wrong.
Yes, we can take any stock depending on the profit it generates for <=K times such that our total cost doesn’t exceeds total amount we have that is W.I am not sure of credibility as i just passed sample cases but it may help you.
Take the code for reference:
def knapSack(W, wt, val, n):
K = [[0 for x in range(W + 1)] for x in range(n + 1)]
# Build table K[][] in bottom up manner
for i in range(n + 1):
for w in range(W + 1):
if i == 0 or w == 0:
K[i][w] = 0
elif wt[i - 1] <= w:
K[i][w] = max(val[i - 1]
+ K[i - 1][w - wt[i - 1]], K[i - 1][w])
else:
K[i][w] = K[i - 1][w]
return K[n][W]
tCases = int(input())
for _ in range(tCases):
n1, k1, W1 = map(int, input().split())
wt1 = list(map(int, input().split()))
profit = list(map(int, input().split()))
newWt = []
newVal = []
val1 = []
for i in range(n1):
tempVal = wt1[i]*profit[i]/100
val1.append(tempVal) #Profit list is made
for i in range(n1):
for j in range(k1):
newWt.append(wt1[i])
newVal.append(val1[i]) #append each value weight and profit K times
n1 *= k1
print(round(knapSack(W1, newWt, newVal, n1)))
- code kart
- signal connection
- best sequence
- lift
- engagement ring
-
hedger
solved None…
can anyone please make me understand faulty keyboard question ?
I am confused with the given test cases .
| denotes cursor position-
my thought : T= empower , S=ew then , for me minimum operations will be : e|w (p+m)-> empow|(m)->empowe|(p+b)-> empower| ,
so total operations will be 5 , am i doing anything wrong ?
You are right from your logic, but i guess they want it for each time you write e or w you have to perform paste which is not optimized, moreover i am not sure,you may be right in this but failing in other test cases.
Did questions repeat from 8th evening in 9th morning during Codevita?
How much time was remaining when you took this screenshot?
Less than 3½ hours
if you have seen the question i think they are considering each word independently.
Does anyone know the logic behind the question Engagement Ring? Thanks.
can anyone have the solution of Tank problem in codevita 2020 ?
Do anyone have the solution of faulty keyboard preferably in python , other languages will also help, PLEASE SHARE!
in the question MAXIMUM PRIZES , is it necessary that opponent order will be in ascending order?
has anyone solved travel cost , if yes please share the logic and code if possible
hey when is your codevita?
Anyone help in the problem Engagement Ring asked TCS Codevita 2020 Round 1.
Problem Description -
Sejal was on a month-long vacation to Europe and has a return trip to India from Lisbon, a city in south west part of Europe. However, a day before the return flight she realizes that she lost her engagement ring. After much contemplation, she decides to go to all the cities she visited to find her ring.
She maps all the cities she visited on a graph with Lisbon being at point (0,0). She then makes a route plan to visit all the cities and return to Lisbon by taking the shortest possible distance. She does not remember having her ring even in the first city she visited so there are high chances that she may have lost her ring in the initial part of her trip also. In case there are more than one routes which have the shortest possible distance, she picks that route in which the first city she visited, comes first. For example, if she visited cities 2,5,7,1,8,3 in that order and routes 0,1,8,3,2,5,7,0 and 0,8,3,1,5,2,7,0 (0 being Lisbon) have the same shortest possible distance then she will choose route 0,1,8,3,2,5,7,0 because she visited city 1 before city 8.
Her travel guide, Harry also offers to help Sejal. Sejal asks him to travel separately on the same route, but in reverse direction such that each city is visited only once. They plan to travel 20 Kms in each city on taxi to search the ring. Inter-city travel is done on trains only.
A secret service officer knows the coordinates of the city that Sejal visited during her the trip in that order. He also knows the city in which the ring is lost but will inform Sejal or Harry only when one of the two is in that city.
He knows the path that Sejal has drawn to visit all the cities and return to Lisbon. With Sejal and Harry following that path and either one of them reaching the city where the ring is lost, the secret service officer will inform the person in that city, that the ring will be 10 km away from their current location. They will travel back 10 km in the same city, to catch the train back to Lisbon. Calculate the total distance traveled by Sejal in her search and her return to Lisbon from that city.
If the ring is found by Sejal, she goes back to Lisbon from that city. If the ring is found by Harry, he informs Sejal on call at that point. If Sejal is in a city (searching in taxi) she returns to Lisbon via train from that city (without searching any further in that city). If Sejal is on train, she will need to complete the journey and then return from that other city. If the call comes at the exact point she is taking a train, she can return from that city itself.
Each unit in the graph is equal to 1 Km. Assume the speed of all trains and taxis is same. Do not consider the decimal values while calculating the distance between two cities, ie. distance will be the floor of the calculated distance.
Constraints -
Floor of the value is to be used while calculating distance between cities
Each city is connected to every other city via trains
Total number of cities <10
Input -
First Line will provide the coordinates (x|y) of cities separated by semicolon ( ; )
Second Line will provide the number of city where the ring is found
Output -
One integer representing the number total distance traveled by Sejal
Time Limit -
1
Examples -
Example 1
Input
0|90;90|90;90|0
2
Output
347
Explanation
Since routes 1,2,3 and 3,2,1 will give the shortest distance, she will select route 1,2,3 as she visited city 1 before city 3. However, Harry will follow the opposite path - 3,2,1. They both will be in city 2 when they will find it. Total distance Sejal covers will be Lisbon to city 1 + 20Kms, City 1 to City 2 + 10 km +10 km and then City 2 to Lisbon. i.e. 90 + 20 + 90 + 20 +127 = 347 km
Example 2
Input
10|70;30|30;80|20;120|75;90|120
3
Output
334
Explanation
Sejal will choose the route 1, 5, 4, 3, 2 with minimum distance of 378 km. However, Harry will follow the opposite path - and will find the ring in City 3. The moment Harry finds the ring, Sejal will be travelling from City 1 to City 5. So she will complete the journey till City 5 and return from there to Lisbon. So the total distance covered by Sejal will be 70+20+94+150 = 334 km
Any help will be highly appreciated . Thank you in advance.
I checked your solution for Railway Station problem.
I want to ask how you came up with such a sleek looking solution?
I came up with rather complicated looking stuff.
While trying to the same thing.
Can you please help me understand how should I practice so that I can come up with cool solutions ( like your ).
You can also be cool for that just go and search on google about this problem. You can find the same problem on GeeksForGeeks
. Just it requires some kind of searching skills, that’s it
.
You can surely come up with better and sleek codes with a lot more practice or you can improve your skill at Googling things just like @gkalyan suggested. 
I was just kidding! @shishir_mangal
. Don’t take it seriously. Of course, it requires a lot of practice to write efficient approach like yours!