DP-9 Book Shop | Knapsack | Problem Solving | Competitive Programming | DSA | CSES

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

КОМЕНТАРІ • 30

  • @omarsherif7184
    @omarsherif7184 10 місяців тому +1

    This is the most effort put in a video concerning knapsack i have ever seen , keep up the good work !

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

    Bhaiya this series is just amazing .... pure material for cp peeps.... but due to endsems I along with many students are now not able to continue with this. So I request you to post every video at higher level only inspite if it's viewership. And I promise that I will covet this after my endsems.❤❤

  • @shauncrasta619
    @shauncrasta619 10 місяців тому +1

    I solved this problem using the traditional pick and not pick method, my dp state was different. But as i went into array descriptions, i started getting clueless. Deciding on a dp state is actually a nice problem. Great series!

    • @simranm.552
      @simranm.552 4 місяці тому

      hi might be a silly question but Time complexity is n.x = 10^3 * 10^5 = 10^8
      why is it not giving TLE? afaik max limit allowed is 10^6 for such questions isn't it? or it is not necessary?

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

      @@simranm.552 The bound is 10^8. 1s = 10^8. So a N*X might just pass, but there are chances of a TLE.

    • @simranm.552
      @simranm.552 4 місяці тому

      @@shauncrasta619 okay got it. thank you:)

  • @anshulsharma3137
    @anshulsharma3137 11 місяців тому +1

    Amazing video Priyansh, Every new video feels better than the previous one 🔥🔥

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

    Thank you Priyyansh for your efforts putting into this , Hope you will continue this playlist till the end with same energy :)

  • @PrinceKumar-gl5fk
    @PrinceKumar-gl5fk 15 годин тому

    UNDERSTOOD

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

    Your course is truly impressive, and the explanation method is excellent.
    I hope you consider developing courses on other topics, such as number theory and range graphs, explained in the same manner.

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

      Surely. However, that would take a lot of time with our current bandwidth. We have our upcoming TLE 9.0 course coming up and all these topics will be covered in Level 3 and 4, you can consider that if you're interested in learning these topics.

  • @devanshpandey3994
    @devanshpandey3994 11 місяців тому +1

    Let's go , op series going .

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

    day 09 too late to complete the video but not missed 😊😊

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

    understood able to code space optimization by myself.

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

    One observation if we reverse our jth loop from x to 0, the code will run perfectly and if we think deeply the way of filling our prev and curr array... then we will realize that there is no need of internal curr array as well. We can use Prev array again for next iteration. I have changed your code to, which I explained above.
    vector prev(x + 1, 0);
    for (int i = 1; i =0 ; j--)
    {
    int w = weight[i - 1];
    int value = val[i - 1];
    int pick = (j >= w ? prev[j - w] + value : 0);
    int skip = prev[j];
    prev[j] = max(skip, pick);
    }
    }
    cout

    • @hardikjain-brb
      @hardikjain-brb 10 місяців тому

      It works both ways as for i=0 it is base case so we get dp[1][all possible j] value giving us dp[2][all j].. so on till dp[n][all possible j]. Nice observation though>!

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

    Can you plz make video on CSES Problem Set after 16 videos also

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

    Amazing content sir !

  • @MayankGour-c9p
    @MayankGour-c9p 5 місяців тому

    understood

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

    understood👍

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

    when Weight

    • @adityaghosh6170
      @adityaghosh6170 3 місяці тому

      Yes it indeed is but according this dp state definition, dp[I][anything] makes more sense since it's already mentioned the maximum weight that we can get from a prefix of length I such that allowed capacity is W

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

    understood

  • @k.k.harjeeth5422
    @k.k.harjeeth5422 11 місяців тому

    Lucid !

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

    #day9

  • @subrat_ryuk2463
    @subrat_ryuk2463 9 місяців тому

    Wont a greedy solution like profit / weight not work here at 1:56 ?

    • @priyanshuchaudhary2313
      @priyanshuchaudhary2313 15 днів тому

      No it won't work as in this problem you can't take a book partially either you have to take it or not take it

  • @aveermukherjee6419
    @aveermukherjee6419 11 місяців тому +1

    #include
    using namespace std;
    int func(int n,int x,int h[],int s[],vector &dp)
    {
    if(n==0 || x==0)
    {
    return 0;
    }
    else if(dp[n][x]!=-1)
    {
    return dp[n][x];
    }
    else
    {
    int a=0;
    if(n-1>=0 && x>=h[n-1])
    {
    a=s[n-1]+func(n-1,x-h[n-1],h,s,dp);
    }
    return dp[n][x]=max(a,func(n-1,x,h,s,dp));
    }
    }
    int main()
    {
    int n,x;
    cin>>n>>x;
    int h[n],s[n];
    for(int i=0;i>h[i];
    }
    for(int i=0;i>s[i];
    }
    vector dp(n+1,vector(x+1,-1));
    cout

    • @manishnangliya8194
      @manishnangliya8194 11 місяців тому +2

      Try bottom up approach with extra space optimization that solution will be accepted