1 00:00:01,290 --> 00:00:03,300 Hi, everyone, welcome to this new video. 2 00:00:03,420 --> 00:00:08,010 So in this video, we are going to discuss the most important question of dynamic programming, which 3 00:00:08,010 --> 00:00:09,490 is 01 knapsack. 4 00:00:10,470 --> 00:00:11,850 So let me try to explain. 5 00:00:11,980 --> 00:00:12,820 What is the question? 6 00:00:13,290 --> 00:00:18,690 So there is one thing I've learned over and the thief wants to steal the item. 7 00:00:18,930 --> 00:00:23,660 So Thief has of it has a knapsack and the weight of the knapsack is engaging. 8 00:00:24,270 --> 00:00:27,980 And these are the food items that is present. 9 00:00:27,990 --> 00:00:28,350 Right. 10 00:00:28,650 --> 00:00:30,100 So a number of items are food. 11 00:00:30,300 --> 00:00:32,650 And this is the weight of each item. 12 00:00:33,540 --> 00:00:34,930 So this is one weights. 13 00:00:35,820 --> 00:00:39,370 So these are bits of each item and these are the prices of the item. 14 00:00:39,540 --> 00:00:40,010 Right. 15 00:00:40,260 --> 00:00:41,150 So this is price. 16 00:00:41,940 --> 00:00:45,820 So our aim is to do what he wants to do. 17 00:00:45,930 --> 00:00:47,820 He wants to maximize profit. 18 00:00:49,110 --> 00:00:49,570 Right. 19 00:00:50,340 --> 00:00:55,200 He wants to maximize profit given he has a knapsack with ten kids only. 20 00:00:56,280 --> 00:01:01,340 So what we need to do, we need to help Steve here and we need to maximize the profit of Steve. 21 00:01:02,820 --> 00:01:04,739 So I hope you have understood this discussion. 22 00:01:04,739 --> 00:01:09,600 And these are items to focus on his ball, second on his apple, third on his banana, and the fourth 23 00:01:09,600 --> 00:01:10,720 one is, let's say, orange. 24 00:01:12,300 --> 00:01:13,920 So how are we going to solve this question? 25 00:01:14,520 --> 00:01:15,660 So it's very simple. 26 00:01:15,670 --> 00:01:17,370 We're told we will use recursion. 27 00:01:18,420 --> 00:01:20,170 So how it will help us here. 28 00:01:20,550 --> 00:01:22,440 So let's talk about this item first. 29 00:01:23,460 --> 00:01:24,780 Let's talk about this item. 30 00:01:26,280 --> 00:01:28,890 Let's try to see how we can solve this. 31 00:01:29,160 --> 00:01:31,890 So the weight of this item is 15 gidgee. 32 00:01:32,670 --> 00:01:35,010 The weight of knapsack is 10 gidgee. 33 00:01:35,850 --> 00:01:38,460 So we cannot pick this item rate. 34 00:01:38,940 --> 00:01:41,720 The item weight is greater than the knapsack weight. 35 00:01:41,850 --> 00:01:43,660 So you cannot pick this item. 36 00:01:44,430 --> 00:01:49,770 So we are discussing one very important condition here, that if the weight of the item. 37 00:01:50,400 --> 00:01:54,120 So we have so this is four and the index is three. 38 00:01:54,330 --> 00:02:00,120 So we are discussing one important condition of the weight of the item is then the knapsack with. 39 00:02:01,790 --> 00:02:06,790 Then you cannot pick this item, right, in that case, it will do we will call the question on the 40 00:02:06,800 --> 00:02:10,300 rest of the items and the question will give us the maximum profit. 41 00:02:11,540 --> 00:02:16,960 So our answer will be our answer will be called recursion. 42 00:02:17,180 --> 00:02:19,240 So let's say the name of the function is knapsack. 43 00:02:19,640 --> 00:02:25,460 So you need to call the rest of the items basically three items, so called the recursion on the rest 44 00:02:25,460 --> 00:02:26,200 of the items. 45 00:02:26,840 --> 00:02:27,260 Fine. 46 00:02:29,060 --> 00:02:30,470 Now let's change the weight. 47 00:02:31,460 --> 00:02:41,330 So let's say instead of 15 gidgee, if the weight of the item is, let's say, six gidgee light, the 48 00:02:41,330 --> 00:02:42,950 weight of item is six gidgee. 49 00:02:42,980 --> 00:02:45,000 Now let's discuss about this item. 50 00:02:45,020 --> 00:02:46,040 So what will happen now? 51 00:02:48,360 --> 00:02:49,430 So what will happen now? 52 00:02:51,260 --> 00:02:58,550 This item has a very thick skin and the weight of the knapsack is engaging, so I can pick this item 53 00:02:59,360 --> 00:02:59,800 right. 54 00:03:00,170 --> 00:03:02,060 So I have two options here. 55 00:03:03,380 --> 00:03:06,410 Pick this item and try to maximize your profit. 56 00:03:07,440 --> 00:03:11,480 Do not pick this item and try to maximize your profit. 57 00:03:13,610 --> 00:03:20,150 So this is the condition we are, including the item we are picking the item and we are not picking 58 00:03:20,150 --> 00:03:22,120 the item, we are excluding the item, right. 59 00:03:22,760 --> 00:03:27,690 So we are excluding the item and everything myself. 60 00:03:27,710 --> 00:03:32,810 See, the weight of this item is sketchy and the weight of knapsack is engaging. 61 00:03:33,020 --> 00:03:37,610 So I can pick this item, but it is not necessary that I will pick this item. 62 00:03:37,610 --> 00:03:37,870 Right. 63 00:03:37,880 --> 00:03:39,110 It's my choice. 64 00:03:39,860 --> 00:03:41,150 It's my choice. 65 00:03:42,160 --> 00:03:45,300 But I can pick this item or do not pick this item right? 66 00:03:45,520 --> 00:03:47,770 Our ultimate goal is to maximize the profit. 67 00:03:48,430 --> 00:03:51,070 So what I'm going to do is I will consider both the cases. 68 00:03:51,400 --> 00:03:56,860 I will consider both cases the case when I am, including the item when I'm picking the item, the case 69 00:03:56,860 --> 00:03:58,650 when I am not, including the item. 70 00:03:59,020 --> 00:03:59,400 Right. 71 00:03:59,530 --> 00:04:03,910 And we will see which case gives us the maximum profit. 72 00:04:04,480 --> 00:04:08,810 So in case, if I am including this item, what will be my answer? 73 00:04:09,430 --> 00:04:11,470 My answer will be I'm including this item. 74 00:04:11,470 --> 00:04:19,029 So the price that I will give, the money that I will gain my profit will be rupees sixty dollars 60 75 00:04:20,230 --> 00:04:20,709 plus. 76 00:04:21,279 --> 00:04:27,220 After picking this item, after you have picked this item, what you need to do, you need to call recursion 77 00:04:27,220 --> 00:04:28,600 on the rest of the items. 78 00:04:28,600 --> 00:04:28,960 Right. 79 00:04:29,620 --> 00:04:32,130 To find out the maximum profit for the rest of the items. 80 00:04:32,410 --> 00:04:34,210 So we need to call recursion. 81 00:04:36,320 --> 00:04:45,200 On the rest of the items, but one more thing now, the weight of your knapsack has become full because 82 00:04:45,200 --> 00:04:48,470 you are including this item and the weight of this item is cagy. 83 00:04:48,680 --> 00:04:50,980 So 10 minus six, that will become four. 84 00:04:51,300 --> 00:04:58,640 So what you need to do so here, in this case, the weight will not change because you cannot pick this 85 00:04:58,640 --> 00:04:58,950 item. 86 00:04:59,390 --> 00:05:00,860 Weight of your knapsack will change. 87 00:05:00,950 --> 00:05:01,760 This is very different. 88 00:05:02,450 --> 00:05:07,370 So in this case, the weight of knapsack will not change, but in this case, the weight of knapsack 89 00:05:07,370 --> 00:05:07,980 will change. 90 00:05:08,450 --> 00:05:09,390 So weird. 91 00:05:09,410 --> 00:05:13,400 Minus six right now. 92 00:05:13,400 --> 00:05:17,780 Your knapsack has a very tough for now in the case. 93 00:05:17,780 --> 00:05:23,780 When I'm excluding this item, when I do not when I'm not picking this item and I'm trying to maximize 94 00:05:23,780 --> 00:05:24,350 the profit. 95 00:05:24,860 --> 00:05:27,640 So in that case, what you will do, what will be your answer? 96 00:05:27,920 --> 00:05:35,630 Your answer will be zero, because you are not picking this item and you will call Dacogen on these 97 00:05:35,630 --> 00:05:36,140 items. 98 00:05:36,140 --> 00:05:36,630 Right. 99 00:05:36,650 --> 00:05:39,830 You will collect on these items rest of the items. 100 00:05:40,080 --> 00:05:46,520 So knapsack, which is our recursive function, the number of items get reduced by one because you are 101 00:05:46,520 --> 00:05:50,450 not picking this item and the weight of knapsack will remain same. 102 00:05:51,470 --> 00:05:51,840 Right. 103 00:05:52,400 --> 00:05:58,910 So what we will do after finding the value for these two, including and excluding what we will do, 104 00:05:59,210 --> 00:06:01,340 we need to take the maximum out of them. 105 00:06:02,210 --> 00:06:06,890 We will take the maximum of include and exclude. 106 00:06:10,440 --> 00:06:16,170 Right will take the maximum because our ultimate goal is to maximize the profit. 107 00:06:16,640 --> 00:06:23,030 So I am calculating the profit when I am including this item, I am calculating the profit when I am 108 00:06:23,030 --> 00:06:24,180 excluding this item. 109 00:06:24,470 --> 00:06:26,690 So that's why I will take the maximum of them. 110 00:06:26,690 --> 00:06:28,540 And that will be my final answer. 111 00:06:29,990 --> 00:06:33,400 Right, so we know all the records. 112 00:06:34,640 --> 00:06:41,870 This is the first recorded evolution when the item where is good and upset with this is the second recorded 113 00:06:41,870 --> 00:06:45,810 revelation when you can pick this item and you are picking the item. 114 00:06:46,550 --> 00:06:52,100 This is the third quarter when you can pick the item, but you are not picking this item. 115 00:06:52,520 --> 00:06:52,890 Right. 116 00:06:53,930 --> 00:06:57,740 And finally, that makes some of these to include gays and exclude a case. 117 00:06:57,740 --> 00:06:59,260 That will be your final answer. 118 00:07:01,150 --> 00:07:04,000 Right, working with a biscuit's. 119 00:07:06,250 --> 00:07:07,520 Let's talk about this case. 120 00:07:07,540 --> 00:07:13,550 So in this case, if the number of items is zero, base case number of items is zero. 121 00:07:13,570 --> 00:07:14,850 We do not have any item. 122 00:07:14,860 --> 00:07:15,880 What would be your profit? 123 00:07:16,180 --> 00:07:20,100 Your profit will be zero if you do not have items to pick. 124 00:07:20,360 --> 00:07:21,790 Then how we can pick the item. 125 00:07:22,150 --> 00:07:23,390 Item does not exist. 126 00:07:23,410 --> 00:07:24,640 So your answer will be zero. 127 00:07:24,640 --> 00:07:25,790 Your profit will be zero. 128 00:07:26,800 --> 00:07:33,490 Similarly, if the weight of the knapsack is zero, the weight of knapsack is zero, you cannot pick 129 00:07:33,490 --> 00:07:34,190 any item. 130 00:07:34,510 --> 00:07:36,880 So in that case, also your profit will be zero. 131 00:07:37,240 --> 00:07:39,100 So these two are the best cases. 132 00:07:39,700 --> 00:07:40,480 Simple, right? 133 00:07:40,780 --> 00:07:42,280 So we now have base case. 134 00:07:42,280 --> 00:07:43,810 We now have recursive case. 135 00:07:43,810 --> 00:07:45,720 Let's start writing the code. 136 00:07:46,150 --> 00:07:52,990 So this problem is basically present on a bit rate zero one knapsack. 137 00:07:53,020 --> 00:07:53,340 Oh. 138 00:07:53,350 --> 00:07:58,390 So one thing that I forgot to explain is what do we mean by zero and one so. 139 00:07:59,370 --> 00:08:07,650 Zero one means here we have written, so zero one means you cannot break diatom, either you will pick 140 00:08:07,650 --> 00:08:11,070 the complete item or you will not pick the item, right. 141 00:08:11,200 --> 00:08:12,270 So it will not happen. 142 00:08:12,270 --> 00:08:13,740 Like you have an apple. 143 00:08:13,740 --> 00:08:20,280 And the cost of Apple is basically, let's say price of item is twenty two hundred dollars and it is 144 00:08:20,280 --> 00:08:20,850 five Gadge. 145 00:08:21,060 --> 00:08:24,090 So and the knapsack rate is two point five Kaju. 146 00:08:24,100 --> 00:08:25,260 So it cannot happen. 147 00:08:25,260 --> 00:08:28,720 Like you will break the apple into half and you take half of it. 148 00:08:28,770 --> 00:08:30,630 No that is not allowed. 149 00:08:30,810 --> 00:08:37,010 So either you pick the complete item or do not pick the item, but you cannot break the items. 150 00:08:37,049 --> 00:08:37,400 Right. 151 00:08:37,650 --> 00:08:39,690 So that is the meaning of a zero one here. 152 00:08:41,820 --> 00:08:46,310 So let's see, let's try to ride the recursive call for this problem. 153 00:08:52,560 --> 00:08:59,640 So these are a few examples given at a ribbon, so the naming is difficult, so is the weight of the 154 00:08:59,760 --> 00:09:00,380 knapsack. 155 00:09:00,750 --> 00:09:04,860 This is the weight of each of the item and this is the price of each of the item. 156 00:09:05,670 --> 00:09:13,590 So the first thing is, let's rename the vector is nothing. 157 00:09:13,590 --> 00:09:17,460 But this is your price at the price of each item. 158 00:09:19,090 --> 00:09:26,820 What is vector be your vector B's veered off each item, right, and what is in Jersey? 159 00:09:26,830 --> 00:09:29,500 So this is the total weight of the knapsack. 160 00:09:31,290 --> 00:09:31,740 Right. 161 00:09:31,950 --> 00:09:39,510 So, as discussed, what we are going to do is we are going to write one knapsack function, so knapsack 162 00:09:39,510 --> 00:09:40,050 function. 163 00:09:43,120 --> 00:09:48,500 This network function, what it will take, it will take how many number of items out there? 164 00:09:48,610 --> 00:09:52,800 That is price, not size or village, not size. 165 00:09:52,810 --> 00:09:53,750 So that will be same. 166 00:09:54,310 --> 00:09:55,780 That is the number of items. 167 00:09:56,830 --> 00:10:02,250 Second is it will take what is the weight of the knapsack? 168 00:10:03,430 --> 00:10:09,190 It will take your place area and it will take your word said. 169 00:10:11,600 --> 00:10:15,350 Fine, so let's write. 170 00:10:16,790 --> 00:10:23,840 Their definition of the function knapsack, this function will return as the maximum profit rate, the 171 00:10:23,840 --> 00:10:24,620 maximum profit. 172 00:10:24,650 --> 00:10:26,750 So how many items are there? 173 00:10:27,590 --> 00:10:30,290 Second, what is the weight of the knapsack? 174 00:10:31,690 --> 00:10:34,850 That is, what is the price of each item? 175 00:10:35,120 --> 00:10:36,610 What is the price of each item? 176 00:10:37,490 --> 00:10:39,950 So vector and price price. 177 00:10:40,880 --> 00:10:43,200 And what is the weight of each item? 178 00:10:43,700 --> 00:10:46,730 So we're adding. 179 00:10:48,390 --> 00:10:56,190 Fine, best case, so the best case that we discussed was if the number of items is zero. 180 00:10:57,320 --> 00:11:04,360 Number of items is zero, Battalia, maximum profit, if you do not have item to pick, then you cannot 181 00:11:04,360 --> 00:11:04,940 pick anything. 182 00:11:04,960 --> 00:11:14,290 So in that case, your profit will be zero simple and other businesses can be if the weight of knapsack 183 00:11:14,290 --> 00:11:19,710 is zero, if the weight of knapsack is zero, you cannot pick any item. 184 00:11:19,990 --> 00:11:21,580 So your profit will be zero. 185 00:11:23,020 --> 00:11:23,580 Simple. 186 00:11:24,190 --> 00:11:26,940 Well, what we can do, we can grab these two conditions here. 187 00:11:27,250 --> 00:11:33,370 So if the number of items is zero or the weight of knapsack is zero, then your profit will be zero. 188 00:11:37,630 --> 00:11:46,240 Now, let's talk about the recursive case, so the first case is basically if the weight of item is 189 00:11:46,240 --> 00:11:52,420 the weight of item is greater than the weight of knapsack, then you cannot pick this item. 190 00:11:52,810 --> 00:11:58,720 So in that case, where you going to do is we will simply call the recursion on the rest of the items. 191 00:11:59,380 --> 00:12:02,040 We are simply calling recursion on the rest of the items. 192 00:12:02,410 --> 00:12:07,380 So a number of items will reduce by one because we cannot pick this item right. 193 00:12:07,780 --> 00:12:14,570 So the knapsack will remain same then the price area, then the witchetty. 194 00:12:15,490 --> 00:12:16,990 So what is this condition? 195 00:12:18,250 --> 00:12:26,470 So if you see here I am talking about this condition, if the weight of the item is lower than the knapsack 196 00:12:26,470 --> 00:12:35,650 weight, for example, if let's say this is 20, so if the weight of the item 20 is greater than the 197 00:12:35,650 --> 00:12:40,200 weight of knapsack, then you cannot pick this item and you will collocation on this part. 198 00:12:40,630 --> 00:12:46,590 So call the equation on a number of items will get reduced by one because you cannot pick this item 199 00:12:46,870 --> 00:12:49,030 and the weight of the knapsack will remain the same. 200 00:12:49,930 --> 00:12:51,550 So that is what I am doing here. 201 00:12:51,550 --> 00:12:51,930 Right. 202 00:12:52,060 --> 00:12:56,800 So if the weight of item is lower than the weight of knapsack, then call that equation on the rest 203 00:12:56,800 --> 00:12:57,500 of the items. 204 00:12:57,880 --> 00:13:00,040 So number of items will get reduced by one. 205 00:13:00,280 --> 00:13:03,260 And this is your price area and you're very steady. 206 00:13:03,820 --> 00:13:06,640 Now, if this is not the condition in the part. 207 00:13:08,160 --> 00:13:12,060 In the early part, you see we have two options here. 208 00:13:13,800 --> 00:13:20,970 If the word is, let's say, six kids, so I have two options here, I can include this item and try 209 00:13:20,970 --> 00:13:26,160 to maximize my profit, exclude this item, and I will try to maximize my profit. 210 00:13:26,400 --> 00:13:31,920 So after including and excluding the maximum profit that I will get will be the maximum of both of them. 211 00:13:32,930 --> 00:13:42,820 So what we need to do, I have option here that I did include this item and find out the maximum profit, 212 00:13:43,570 --> 00:13:49,970 I did include this item and find out the maximum profit or exclude this item and find out your maximum 213 00:13:49,970 --> 00:13:50,420 profit. 214 00:13:53,660 --> 00:14:01,520 So exclude the item and find out the maximum profit, right, and what will be your answer, your answer 215 00:14:01,520 --> 00:14:09,860 will be make them off the maximum profit that you can get by, including the item or by excluding the 216 00:14:09,860 --> 00:14:10,250 item. 217 00:14:13,070 --> 00:14:17,970 Now, what we need to do, we need to find out the value of include and exclude. 218 00:14:18,890 --> 00:14:20,990 So what will be the value of include? 219 00:14:26,560 --> 00:14:30,760 Let's first talk about include, right, including the item. 220 00:14:32,240 --> 00:14:40,490 See if you include the item, for example, I am including this item, so 60, my profit will be 60. 221 00:14:40,520 --> 00:14:43,060 I am taking this item so I will get a profit of 60. 222 00:14:43,400 --> 00:14:44,580 So what is this, 60? 223 00:14:44,930 --> 00:14:46,280 This is your price at. 224 00:14:46,700 --> 00:14:46,980 Right. 225 00:14:47,500 --> 00:14:54,800 So the price of the item, the price of the item, plus the collocation on the rest of the items. 226 00:14:54,800 --> 00:14:55,160 Right. 227 00:14:56,560 --> 00:14:57,130 So. 228 00:14:59,680 --> 00:15:10,480 Place of and minus one, great plus, we need to call the on a list of the items so knapsack number 229 00:15:10,480 --> 00:15:17,890 of items will get reduced by one because you have picked this item also since you have picked this item, 230 00:15:18,430 --> 00:15:23,560 since we are picking this item, the weight of this item was six CGY and the weight of knapsack was 231 00:15:23,560 --> 00:15:30,970 langauges or 10 minus six for the weight of a knapsack will decrease, the weight of your knapsack will 232 00:15:31,060 --> 00:15:31,630 decrease. 233 00:15:33,370 --> 00:15:41,200 So the weight of knapsack will become the total weight minus the weight of this item find. 234 00:15:43,150 --> 00:15:46,780 But said will remain same, where today will remain same. 235 00:15:47,290 --> 00:15:50,670 So this is the record for including item. 236 00:15:51,280 --> 00:15:55,310 Let's talk about excluding the item when you are not picking this item. 237 00:15:55,810 --> 00:16:02,190 So when you are not picking this item, you will get zero profit because you are not picking item. 238 00:16:02,530 --> 00:16:07,600 Plus, you are calling the equation on the rest of the items, the rest of the three items. 239 00:16:08,770 --> 00:16:09,220 Right. 240 00:16:09,670 --> 00:16:16,030 Calling the equation on just of the three items and your knapsack rate will remain same because you 241 00:16:16,030 --> 00:16:18,910 are not picking the element or picking the item. 242 00:16:19,810 --> 00:16:24,000 So simply you are calling the recursion. 243 00:16:24,280 --> 00:16:30,310 So a number of items will get reduced by one because you are not picking this item, the knapsack which 244 00:16:30,310 --> 00:16:36,470 will remain same because you are not picking the item and that is your price area and that is your way. 245 00:16:36,490 --> 00:16:38,740 It's very simple, right? 246 00:16:38,990 --> 00:16:40,580 That is the complete code. 247 00:16:40,930 --> 00:16:44,560 So let's test our code and then we will submit. 248 00:16:50,620 --> 00:16:54,460 So our goal is passing basic test cases. 249 00:16:54,490 --> 00:17:01,040 Now let's try to submit our code so most really what will happen, our code will encounter random sorry, 250 00:17:01,300 --> 00:17:02,260 not runtime error. 251 00:17:02,710 --> 00:17:08,710 The time limit exceeded because our solution is recursive and right. 252 00:17:08,930 --> 00:17:12,069 So we are getting time limit to delay. 253 00:17:13,599 --> 00:17:13,960 Right. 254 00:17:14,950 --> 00:17:17,780 So and that was pretty obvious. 255 00:17:18,520 --> 00:17:20,200 So this is recursive solution. 256 00:17:21,020 --> 00:17:23,460 So that's why we are getting excited. 257 00:17:24,310 --> 00:17:31,930 Now, what do you want to do is in the next video we will convert this recursive solution into a solution, 258 00:17:33,790 --> 00:17:34,130 right? 259 00:17:34,620 --> 00:17:35,110 It will, right. 260 00:17:35,110 --> 00:17:40,070 The Dynamic Programming Board will convert this recursive coding to binding programming code. 261 00:17:40,480 --> 00:17:45,520 So one more thing that I want to discuss before ending this video is basically so here. 262 00:17:45,820 --> 00:17:54,940 What I'm assuming we are assuming that we have only one Apple, we have only one banana, we have only 263 00:17:54,940 --> 00:17:55,830 one orange. 264 00:17:55,840 --> 00:17:57,270 We have only one bowl. 265 00:17:57,970 --> 00:18:02,530 And if I'm picking the apple, then I cannot pick Apple again later. 266 00:18:02,590 --> 00:18:12,100 So here our inception in this question is we have one copy of each item made, one copy of each item. 267 00:18:13,300 --> 00:18:18,850 Now let's see if we have infinite apple, we have infinite orange. 268 00:18:19,630 --> 00:18:24,740 We have infinite bananas and we have infinite balls. 269 00:18:26,140 --> 00:18:30,000 So what will happen, let's say, if your TV is basically going into an Apple store? 270 00:18:30,010 --> 00:18:33,240 So there will be many laptops of exact same configurations. 271 00:18:33,550 --> 00:18:38,980 So basically in this question that I want to say, it is let's say I am modifying this question, do 272 00:18:38,980 --> 00:18:43,650 we have infinite we have infinite copies of each item, right? 273 00:18:43,840 --> 00:18:45,610 We have infinite apples. 274 00:18:46,450 --> 00:18:49,180 We have infinite range between finite bananas. 275 00:18:49,180 --> 00:18:51,630 We have infinite balls. 276 00:18:52,150 --> 00:18:58,750 So what I want to say here is if I am picking the item once, then here I am doing I cannot pick the 277 00:18:58,750 --> 00:19:00,730 item twice the rate. 278 00:19:01,030 --> 00:19:09,220 I can pick the item only once, but since now we have infinite copy of each item so I can pick one item 279 00:19:09,220 --> 00:19:10,410 more than one time. 280 00:19:10,420 --> 00:19:10,840 Right. 281 00:19:11,380 --> 00:19:17,670 So how we are going to modify this code for solving this problem when we have infinite copy. 282 00:19:17,680 --> 00:19:18,820 So it's pretty simple. 283 00:19:19,270 --> 00:19:23,950 What we are going to do is this is basically when you cannot pick this item, this is basically when 284 00:19:23,950 --> 00:19:29,470 you are not picking this item and this is the only recursive relation where you are picking the item. 285 00:19:29,800 --> 00:19:36,640 So what you are doing after picking the item, you're calling it because the rest of the items we are 286 00:19:36,640 --> 00:19:39,520 calling recursion on the rest of the item, and that is wrong. 287 00:19:39,610 --> 00:19:42,940 This condition has to be changed when we have infinite copy. 288 00:19:43,240 --> 00:19:43,930 So what do we do? 289 00:19:43,960 --> 00:19:46,330 We will not call the question on rest of the items. 290 00:19:46,630 --> 00:19:48,880 We will call recursion on all of the items. 291 00:19:49,860 --> 00:19:56,350 So for infinite copy, if you encounter one question and the question mentioned that you have infinite 292 00:19:56,350 --> 00:20:01,710 copy of each item, you can pick one item more than one times, basically infinite number of times. 293 00:20:02,020 --> 00:20:06,880 So the only change that you need to do in this code is basically, instead of calling that equation 294 00:20:06,880 --> 00:20:08,830 and minus one, you will call recursion on. 295 00:20:08,840 --> 00:20:16,260 And that is the only change that you need to do in this question for basically this infinite copy. 296 00:20:16,630 --> 00:20:16,970 Right. 297 00:20:18,220 --> 00:20:23,570 So, yeah, that's the last thing that I want to discuss about this question, the recursive code. 298 00:20:23,890 --> 00:20:28,530 So in the next three days or we will try to write the dining programming code for this problem. 299 00:20:29,290 --> 00:20:31,140 So this is all about this video. 300 00:20:31,240 --> 00:20:32,520 I will see you in the next one. 301 00:20:32,620 --> 00:20:33,130 Thank you.