DP-5 Coin Combinations 2 | Problem Solving | Competitive Programming | DSA | CSES

Поділитися
Вставка
  • Опубліковано 8 лис 2024

КОМЕНТАРІ • 64

  • @PriyanshAgarwal
    @PriyanshAgarwal Рік тому +45

    Wishing you all a very Happy Diwali. Hopefully with this series you will be able to eliminate your fear of DP by the end of November.

    • @abhijeetfasate6131
      @abhijeetfasate6131 Рік тому

      Happy Diwali to you 🎇🎇🎇. P.S. : There's a great article for this problem on USACO

    • @anishgiri2806
      @anishgiri2806 Рік тому

      A Very Happy Diwali Bbhaiya. Thank you very much this wonderful series I am able to understand everything.💚

    • @neelkhandare5057
      @neelkhandare5057 Рік тому

      yes

  • @dank7044
    @dank7044 Місяць тому

    You are literally a godsend priyansh. Its due to you i have become a specialist in codeforces and DP makes sense to me. Thank a lot for everything you have been doing for the community. i hope someday i become good enough to become a mentor at TLE and meet you.

  • @AliHossain-j7k
    @AliHossain-j7k 11 місяців тому +2

    After watching 3rd time this video, I understood dp[i][k]. why happend this one could not understand before, now it's clear to me. Thanks a lot.

    • @TLE_Eliminators
      @TLE_Eliminators  11 місяців тому +5

      The trick is always to focus on the meaning of the state and you will find it relatively easier to follow the video and also better understand your own implementation.

    • @nishanttyagi3665
      @nishanttyagi3665 7 місяців тому

      can some one please help me why is this giving tle
      Here dp[i][j] = total ways to construct i using first j element of the choice(v) array
      void send(){
      int n,x;
      cin>>n>>x;
      vectorv(n);
      for(int i=1;i>v[i];
      vectordp(x+1,vector(n+1));
      for(int i=1;i

  • @sauravfarkade7032
    @sauravfarkade7032 Місяць тому +1

    Just amazing man!!
    thanks bhaiya for the wonderfull series!

  • @amitabhsharma6312
    @amitabhsharma6312 Рік тому +1

    Extremely good and simple explanation, would love to reach the end of this playlist....

  • @amaansiddiqui311
    @amaansiddiqui311 11 місяців тому

    Just Amazing ! really learning and enjoying this series bhaiya. Thanks a ton for this level of content!!

  • @YerramArun
    @YerramArun Рік тому +2

    Understood bhaiya❤❤

  • @neelkhandare5057
    @neelkhandare5057 Рік тому

    best lecture series on DP, bhaiya I think you should add Space optimisation

  • @sh_sho1kat
    @sh_sho1kat 10 місяців тому +3

    Is there any recursive solution possible for this problem? getting tle for this constraints.

  • @musaddikkhan9720
    @musaddikkhan9720 Рік тому +1

    Day05 of DP series :- In whole Video what i like most is the explnation of the flow of Loops..... Doubt is why we use pick - not pick previous code ke jaise iterate karege aur set me store karege to nhi chalega kya ? and sir give me small test case for dry Run.... Thanks For Better Explnation fear kam ho raha ki without recursion i can write iterative code 😊😊😊😊😊😊

    • @musaddikkhan9720
      @musaddikkhan9720 Рік тому +1

      And Also in the case of if we have don't allow to use same number again so we will make our transition like that
      dp[i+1][k] for skipping
      dp[i][k]
      dp[i+1][k-ci] for picking
      am i right sir ?

  • @AnmolGupta-oj4lm
    @AnmolGupta-oj4lm 8 місяців тому

    Understood

  • @aniketpriyadarshi2801
    @aniketpriyadarshi2801 Рік тому +1

    understood.

  • @shashikiran9388
    @shashikiran9388 11 місяців тому

    understood

  • @amandixit8342
    @amandixit8342 11 місяців тому

    Bhaiya all the problems i solved of cses except 4 last problem and first 12 problem at atcoder as you said in the video which is what topic should be done in order to become the expert , i am not comfortable and lil fear of story form of problem , what should i do ?

  • @khitijkarmakar
    @khitijkarmakar Рік тому

    Can we watch this series , if I am a complete beginner to DP?
    I'll start learning DP soon after my exams.

  • @gayatrikanojia
    @gayatrikanojia Рік тому

    Can u explain also explain about solving using push dp. It is easy to think and there is less bothering about the indices. But it fails in some cases. Can u explain it also???

    • @TLE_Eliminators
      @TLE_Eliminators  Рік тому

      Can you please elaborate a bit. What is the meaning of your state in the push dp context.

    • @gayatrikanojia
      @gayatrikanojia Рік тому

      @@TLE_Eliminators No no, I am just requesting to please explain about the push dp approach also if possible as it is easy to think. But it has some order of evaluation concern. Which is difficult to understand. It would be helpful if Priyansh bhaiya can explain a little bit about that also.

    • @TLE_Eliminators
      @TLE_Eliminators  Рік тому

      You don't need that push dp concept to solve any of these problems. There is a problem (money sums) which is related to what you're talking about and Priyansh is going to cover that so you might get an idea of that in that video.

  • @PratikDongare-bh2vs
    @PratikDongare-bh2vs Рік тому

    understood

  • @crazzyy122
    @crazzyy122 Рік тому

    Why recursion+memoized solution gives TLE for max constraints?

    • @TLE_Eliminators
      @TLE_Eliminators  Рік тому +1

      The constraints on CSES are pretty tight so recursive codes usually give a TLE. We suggest coding these problems iteratively and also working on building the iterative dp mindset.

    • @crazzyy122
      @crazzyy122 Рік тому

      @@TLE_Eliminators okk will do iteratively. Thanks for replying

  • @amanraj4251
    @amanraj4251 4 місяці тому

    background music name please

  • @manindhra748
    @manindhra748 Рік тому +1

    #day5

  • @crimemastergogo710
    @crimemastergogo710 6 місяців тому

    why are we returning dp[0][x]??

    • @piedepew
      @piedepew 5 місяців тому +1

      dp[0][x] = make sum = x from 0th coin to n-1th coin , apply this to our state definition
      dp[i][j] = make sum = j from ith coin till n-1st coin (0 based indexing of coins array)

  • @akshattyagi3679
    @akshattyagi3679 4 місяці тому +2

    O(n^2) is giving TLE

    • @pushpendrahpx
      @pushpendrahpx 4 місяці тому

      May be you'll be doing dp[sum][n] instead do dp[n][sum] => This improves the time complexity by a lot.

    • @lt0019
      @lt0019 4 місяці тому

      ​@@pushpendrahpx but why?

    • @pushpendrahpx
      @pushpendrahpx 4 місяці тому

      @@lt0019 I checked online the reason is because of Caches getting misses in columnMajor Array, if you'll change it with dp[sum][n] => More no. of bytes are can be read sequentially.

  • @Negijicoder
    @Negijicoder 6 місяців тому +1

    yehi same code mai kab se recursive se kr raha hu..... sahi kyu nahi aa raha.. or i'm damn sure mera code sahi hai..!!

    • @tajuddinmalnas1903
      @tajuddinmalnas1903 4 місяці тому +1

      bhai woh cses pe recursive code submit nhi hota pata nhi kyu

    • @Negijicoder
      @Negijicoder 4 місяці тому +1

      @@tajuddinmalnas1903 bro i find out.. (Just not don't use long long in place of int..)

    • @Adityasharma-ii3dg
      @Adityasharma-ii3dg 3 місяці тому

      @@Negijicoder thanks buddy

  • @nagarjundevulapalli8624
    @nagarjundevulapalli8624 2 місяці тому +1

    Difficult to understand, need some more effective explanation

  • @anonymousanonymous7507
    @anonymousanonymous7507 Рік тому

    tabulation?

  • @srinivasbeta8202
    @srinivasbeta8202 Рік тому

    after watching the video multiple times(hours) im still not understanding why dp[i][sum] = dp[i+1][sum] + dp[i][sum-Ci] and how the picked and skipped is working ...anybody please tell me.......

    • @TLE_Eliminators
      @TLE_Eliminators  Рік тому +1

      Let's start by understanding what is the meaning of the state. What do you think is meant by dp[i][sum]?

    • @srinivasbeta8202
      @srinivasbeta8202 Рік тому

      @@TLE_Eliminators no of ways to make sum by using i to n coins

    • @TLE_Eliminators
      @TLE_Eliminators  Рік тому +1

      Then see there are two choices now,
      1. You decide to skip coin i, in this case you will have to make the same sum with coins from i + 1 to n, hence dp[i+1][sum]
      2. You decide to pick coin i, in this case you can again pick up coin on the next steps but your sum reduces by the value of the coin, hence dp[i][sum- ci]
      Clearly, if there are 2 possible ways, you would just add up both of them to find your answer for dp[i][sum].
      Does this help?

    • @MrinalAnand-y9q
      @MrinalAnand-y9q 11 місяців тому

      @@TLE_Eliminators yes great explanation bhaiya

  • @nishanttyagi3665
    @nishanttyagi3665 7 місяців тому

    can some one please help me why is this giving tle
    Here dp[i][j] = total ways to construct i using first j element of the choice(v) array
    void send(){
    int n,x;
    cin>>n>>x;
    vectorv(n);
    for(int i=1;i>v[i];
    vectordp(x+1,vector(n+1));
    for(int i=1;i

    • @SlapB0X
      @SlapB0X 6 місяців тому

      i think its not about the time complexity but more about space complexity.
      Your solution's space complexity is O(n*x) , while the accepted space complexity is O(x)

    • @nishanttyagi3665
      @nishanttyagi3665 6 місяців тому

      @@SlapB0X actually the solution is getting submitted when the dp[x][n] is changed to dp[n][x] and the the loops are also reversed. whereas with the upper solution i t is giving tle

    • @_bittu_
      @_bittu_ Місяць тому +2

      ​​@@nishanttyagi3665it has something to do with the way memory works at lower level. If you have to make an array of size SxL make it as array[S][L] instead of array[L][S], where S is the smaller and L is the larger dimension respectively. It is a bit faster.

    • @nishanttyagi3665
      @nishanttyagi3665 Місяць тому

      @@_bittu_ I read this on stackoverflow too. This is correct thank you.

    • @craftyblue8576
      @craftyblue8576 Місяць тому

      @@_bittu_ Thanks!

  • @AakashShanker
    @AakashShanker 7 місяців тому

    Understood

  • @HimanshuSharma-gf4ij
    @HimanshuSharma-gf4ij 10 місяців тому

    understood