Magic Cows | Dynamic Programming | Adhoc | Interview problem

  Рет қаралды 48,282

WilliamFiset

WilliamFiset

Күн бұрын

Пікірлер: 53
@marvinroche1351
@marvinroche1351 22 сағат бұрын
Interesting solution for the approach. Thank you for the video. Another solution : F = sum([2 ** max(d - (math.ceil(math.log2(C / x)) - 1), 0) for x in F0]) with C : max cows per farm F0 : (ex : [1,1,2,1,2]) initial cow repartition per farm d : day of control Explanation : a farm starts doubling when F0[ i ] * 2 ^ d > C. Before that it stays at 1 In a less compressed way : import math from typing import List def calculate_farms(N: int, C: int, F0: List[int], d: int) -> int: """ Calculate and print the intermediate steps for the number of farms on a specific day. :param N: Number of initial farms :param C: Maximum number of cows per farm :param F0: List of integers representing the number of cows on each initial farm :param d: The day to calculate the number of farms :return: Total number of farms on day `d` """ # Calculate threshold days for splitting dc = [math.ceil(math.log2(C / x)) - 1 for x in F0] print(f"Threshold days (when farms will split): {dc}") # Calculate the number of farms on day `d` F = [2 ** max(d - di,0) for di in dc] print(f"Number of farms on day {d}: {F}") # Total farms total_farms = sum(F) print(f"Total number of farms on day {d}: {total_farms}") return total_farms N = 6 C = 5 F0 = [1, 1, 2, 1, 2] d = 3 result = calculate_farms(N, C, F0, 0)
@ialpha6431
@ialpha6431 4 жыл бұрын
Great one ! I guess this channel is the next Khan Academy.
@markkaravan4245
@markkaravan4245 4 жыл бұрын
This may be the best programming series I've seen online and I've seen a lot. Amazing work, William!
@itsahandle
@itsahandle 4 жыл бұрын
This channel is so underrated man, I hope more people notice your hard work and learn something from u, thanks for the video keep it up!!
@mzmzgreen
@mzmzgreen 4 жыл бұрын
I love this! More dp please! :) Also minimax is a topic that isn't so popular in tutorials. You're a great teacher, keep up the good work!
@perseus1511
@perseus1511 4 жыл бұрын
Hi ,thank you so much williamFiset ,with you I learn what in university teachers never gonna teach me. Greetings from Peru and thanks for the subtitles.
@abhishek.rathore
@abhishek.rathore 3 жыл бұрын
Cowtosis: The process common in cows which leads to there duplication overnight. Usually caused by overeating of fresh grass.
@pulgupta
@pulgupta 4 жыл бұрын
Thanks William, you have a very nice way of explaining things. Your animations are great at conveying the idea before looking into code
@treyi1794
@treyi1794 4 жыл бұрын
Hey, I absolutely love your content!! can you please please do an exclusive course on dynamic programming- the theory, problem-solving methods and frequently asked interview problems.
@kmchary1181
@kmchary1181 2 жыл бұрын
The absolute best series.
@bhawnabharti4369
@bhawnabharti4369 3 жыл бұрын
Great contents on your channel. I am big fan of your teaching style. please add some more dp problems. It is very very helpful for strugglers
@thallium54
@thallium54 4 жыл бұрын
Wow I didn't realized it could be solved using dynamic programming during the contest. That's such an elegant approach! Here I would like to describe my approach which may be a bit easier to think about: The key observation is that once an original farm is full for the first time, the number of farms needed to hold all the cows would double everyday. Knowing this we could calculate the answer without tracking the number of cows. The time complexity is O(NM), so either of these two approach may be faster under different constrains.
@rithwiksrk462
@rithwiksrk462 4 жыл бұрын
yes I did the same thing
@sikandarbakht2076
@sikandarbakht2076 4 жыл бұрын
Please make a series of dp from scratch..... Thanks
@shashanktiwari4442
@shashanktiwari4442 4 жыл бұрын
Awesome pls make a complete series including codeforces problems also will help a lot
@alirezakamyab851
@alirezakamyab851 3 жыл бұрын
Nice channel, keep the dynamic programming coming
@mohamedshehata8972
@mohamedshehata8972 2 ай бұрын
great work man, thanks
@sograb
@sograb 3 жыл бұрын
I was trying to find some tutorial about DP. Udemy and Pluralsight has such videos but despite they're not free, they're not as good as your videos. These visual explanations are so great. Thanks a lot! Could we support you anyhow?
@adityamishra4458
@adityamishra4458 4 жыл бұрын
please make competitive programming series
@puneetkumarsingh1484
@puneetkumarsingh1484 4 жыл бұрын
An interesting variation of this problem will be like: Whenever the number of cows increases the maximum capacity, he creates a new farm for the extra cows with everything else remaining the same. It is like he is trying to maximize his efficiency of farm.
@oisindavey2340
@oisindavey2340 3 жыл бұрын
Great video! I think that this can also be solved using fast matrix exponentiation in O(Q•logD•log^3C).
@madhukiranattivilli2321
@madhukiranattivilli2321 3 жыл бұрын
If total number of farms with
@prasannathapa1024
@prasannathapa1024 2 жыл бұрын
Some other approaches as well #include using namespace std; #define loop(i,x,n) for(int i = x; i < n; ++i) #define inp(f,n) loop(i,0,n){cin>>f[i];} int main() { int c,n,m; cin>>c>>n>>m; int f[n], q[m]; inp(f,n); inp(q,m); loop(j,0,m){ long long ans = 0; loop(i,0,n) ans += (1LL
@algorithmscasts902
@algorithmscasts902 4 жыл бұрын
Excellent explanation, thank you.
@chenjason2598
@chenjason2598 Жыл бұрын
Awesome!
@srini2010srini
@srini2010srini 4 жыл бұрын
Cool explanation. Thanks.
@benzhang8916
@benzhang8916 4 жыл бұрын
Hi are you going to illustrate some questions on LeetCode
@runnerup15
@runnerup15 4 жыл бұрын
given the problem statement i dont even really know where to begin without watching the whole video. i think im learning this out of order maybe there must be something else i need to know before jumping into questions like this
@uXXair
@uXXair 4 жыл бұрын
I don't get it. How are we supposed to derive such solutions? Is it just practice, practice, and practice?
@manngondaliya4704
@manngondaliya4704 4 жыл бұрын
Good work man 👍👍👍👍
@AK-vx4dy
@AK-vx4dy 9 ай бұрын
Maybe i'm wrong, but i think we don't need dp table to all days, but only 2 rows, if we will store the number of farms in query table and reuse rows ?
@ialpha6431
@ialpha6431 4 жыл бұрын
Hi William, Could it be possible for you to add a new playlist explaining some of the good stuff from computational geometry ?
@RedionXhepa
@RedionXhepa 4 жыл бұрын
Nice work !
@astrallee7460
@astrallee7460 4 жыл бұрын
thanks !! really!!
@Red___Beast
@Red___Beast 9 ай бұрын
amazing
@subee128
@subee128 8 ай бұрын
thanks
@prabhavrajeev9682
@prabhavrajeev9682 4 жыл бұрын
Please make a video on manachers algorithm
@bluejay9269
@bluejay9269 4 жыл бұрын
hey William, I noticed the problem vault website is down. What happened? I enjoyed using it for practice.
@WilliamFiset-videos
@WilliamFiset-videos 4 жыл бұрын
Problem vault was recently turned down because of the cost of renewing the domain was going to cost an outrageous amount, and we haven't yet bothered to find a new place to host it.
@puneetkumarsingh1484
@puneetkumarsingh1484 4 жыл бұрын
@@WilliamFiset-videos What is Problem Vault?
@lkri7951
@lkri7951 2 ай бұрын
Isn't this a simple math problem, why use dynamic programming?, ceil((total cows on day 0 × day of visit × 2) ÷ max number of cows per farm)
@priyanka.sarkar
@priyanka.sarkar 4 жыл бұрын
Hi William, your videos are just amazing. I had one question, I tried submitting the solution in the website but I did not get all the TCs correct. Link to the submission : open.kattis.com/submissions/6501122
@parthsaraswat9744
@parthsaraswat9744 3 жыл бұрын
i like this intro song
@adhishmalviya2408
@adhishmalviya2408 4 жыл бұрын
Videos are in 4K
@ragingpahadi
@ragingpahadi 4 жыл бұрын
Cowmitosis 😁😁😁
@lovesegtree
@lovesegtree Жыл бұрын
your sound is small can you speak louder?
@andreamengoli4656
@andreamengoli4656 3 жыл бұрын
Cow Mitosis ahahha
@SC1240
@SC1240 4 жыл бұрын
this shit rules
@aa-xn5hc
@aa-xn5hc 3 жыл бұрын
I dislike Kitties very much because it has got a very outdated version of C#
Tiling problems [1/2] | Dynamic Programming
16:38
WilliamFiset
Рет қаралды 40 М.
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 9 МЛН
Sparse Table Data Structure
23:18
WilliamFiset
Рет қаралды 32 М.
Topological Sort | Kahn's Algorithm | Graph Theory
13:32
WilliamFiset
Рет қаралды 134 М.
5 Simple Steps for Solving Dynamic Programming Problems
21:27
Reducible
Рет қаралды 1,1 МЛН
Python laid waste to my C++!
17:18
Sheafification of G
Рет қаралды 181 М.
Writing Code That Runs FAST on a GPU
15:32
Low Level
Рет қаралды 574 М.
How to Solve ANY LeetCode Problem (Step-by-Step)
12:37
Codebagel
Рет қаралды 334 М.
A Deep Understanding of Dynamic Programming [Intro / Overview]
29:03
Lowest Common Ancestor (LCA) Problem | Eulerian path method
17:02
WilliamFiset
Рет қаралды 46 М.
Towers of Hanoi: A Complete Recursive Visualization
21:13
Reducible
Рет қаралды 505 М.