0% found this document useful (0 votes)
35 views11 pages

DP - ClassII - Notes - 7th June 2023

Uploaded by

Sisir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
35 views11 pages

DP - ClassII - Notes - 7th June 2023

Uploaded by

Sisir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 11
escnty ez— 07/06/2033 a Ofn_change problem (Leetcode 322) f/p> coins = Cis 255) Qmount = 12 O/pa 3 (5+1+5) © minimum no. ef coins thave te yetunn -i. Sf we aut notable +e make the amounts we Sn. £ — which 1s equal +e the «): calls —_— ee cofna and hence” 3 cotys ma Fhe. for each node. We ~ a a Can say thot we — ‘te Mun on for Qoob Pram “0 to ne a Ico/ns + _— Dry un 7 Bt is Import ° om Tamount becomes O swe hove Succers, the — — . . & stove the ‘minimum— prsSp—Sel9s eee ny vuaiicu wiur vam . \\\ \\\ classmate coins > Cl>2I itonget /amount = 2G) 2 Overterpping. - ‘ubbroblems 1S) iz _ Coe ES (Oy OF G5, OTE = @) €)* _ Store An min Tin — Store Min tien Recuoalve cast —for cach anova valle CSimple Sor fook pobesn) the coins antay. [Lf lint colve Ree Cvector 4 ovaiiicu wiur van classmate. Date__~ Bese. =| 3 a xyetwin minis 3 i (vector & Colns s int_omourt)l nt coin Change. Z Cobh. Xha funder. : 7 int ang = solve Ree (coins » Amount) (f Cans == INT-MAX) xetuin — 15 Directed by question wetuxnnh ans 3 3 int Solve TopDown. (vector & coins s vin amount, vector 4 dp) f if Camount ==0) setunn O 5 if (amount <0) xveturn INT-MAX) WSkep 38 Check if ans olneady if (db (amount | = - 1) . yetwin db lamount]s fot mint = INT- MAX) on for (int C205 ( dp) 5 — / If Cans | =ZNT-MAX) F 3 Mint = min Cminr, |+ans)2—~ z Y / Step 2 % Update tn_dp Gray. ovanneu wiuram classmate. A 4 Ap Camount] = mini’: _ Attwin db Camount) 5 mk __|ine corn Ch (vector & Coing » Int amount){ WStep |i Create dp asviay amount chaaying in. vectoy db fone i, Int_ans = Solve TopDown (colns, amounts dp)s if Cans = = ENT-MAX) webusn —\s _ Wetwsn Qns J Te = OCamount) 3 Sc= Ol(n+n) [iit ttt [Bottom sup approach CTabulatien) aa We need te Bnous—by which valus should wwe linthalige the db away here. dp arian 4 1 kontainina minimum no-s, coins 4 hence store ENT —MA X_jnitiolhy lint solve Tah Cvector & coins, intamoupt)i- W/ Step ti Crea dp wunog “veckoy db Camount +15 ENT- MAX) 5 WStep 2 + Opsenve hore cane et tob-down Aplo}=0 4 WStep 3% Reverse fpow fn top-down obbyoo/ | foy (int rats (2 =amount J cee) t iG - —— , - Sorat Fox (ink a0 1s ce0ne Sipe bhi a : : if. Ce~ coins (42 2=0 Kbdp ee coins (4) |=INT- MAX) ~ i : i. =a (c-coins CG IJ > ap Ct} = min (Apt, Itans) 3 7 M(t il fy j vvuaimicu wiur vam classtate Date, Pege a, 3 — 3 ; — retwin db Camount Js 7 5 =— int coin Change Cicector & coins s int _amount)i [nt_ang = Solve Tab (coins s amount) > if (ang = = INT. MAX) yetusn —( vetuyn ans + 3 Dry sun = coins 4 Cis 25 5) amount > 7 ES 212} [ale a a OE ee dp Co} = 0 negohive index Ip C1) = min (+l, xXx) a2 g Tefahive thdex aa laplad = Min (itt, 0+2, xX) = ZL __ b(3] =min C442, 441, x) 2 Q _ Epl4d= min Ci+2, (+1, x) = 9 (5) =min (Qt! , Atl, 04) = 4 Hplé) = min Ctl, 2+), 1+1) = 2 Idp(D) = min (atl, I+), /+/) =a : Zz Y Fina answen ~~ vuaimicu wiur Gam 4 Ap C4) = min (202 ys 2) U x 7 go ere INdex berincd y > go two index behind 27 9° Hive index behinck Coins size © Ly | OCamount X_N) OCn) Tc sc Space spbimigaher—— Hene Shace a - is not possible as Ab (Ct) _clepends en. ea C= coina j.J] and coina C7.) 18 not_a extain value. Here we canst a a - _| woblem. _CLéetcode _198) 4 ipa Cl, 22 3219 lp 4 Ct3 =4) | A robbex can?t xob_adjacent houses 60 sols ight Wie have tox ebush—Max! mune EPS ~~ Yobher can. —tob_at_same_nighh ia [3 [2] include (exclude wii L [2 3 2] exclude includ! 3 [t le p p E] oa scease cone) £ S — Bc —svarmmen wir van 7 Ce include 3 2° moves by 2 inde sc : exclude 7 4° moves by 4 _fndex ae Recunai Co. \ Oe int solve Ree (vector & numa, int nt Z/ Bane case i Invalid howe A hence nolhing if (n <0) te stead o yetuun © 5 if (n = =0) vetunn numa [Co] 4 U Inelude casa. \ _ — Int fnclude =nums (n) +Solve Ree (nurs, n-&)5 _ xclude cosh int exclude = O + Solve Rec Chums pati ; vetunn max (include , exclude) _— int vob (vector 2 numa) f » int p= nums- Size () =} ee xyebunn solve Rec (numa, n) 5 3 S te ee S Tep down. abbroach. ‘nt _solve Tc op Down (vector Bramy nen — vector int2&dp) £ Bare Case i£ (n 2 numa) f == —| = | = num. PIP ad ikea Tn *retaraton — — : —L__ vector rQacl ol J : — Lint Solve Tab (vector < int > & NUM > Int. n) £ a — Seep ts Crea. ap amare will wovk wilh IE “vector =0) —_ temb = dp Cr-a05 a Int_include = temp tnums Ct’) 5 a int exclude = O+ Ab CL- 195 dp (22 max (include , exclude) j j vetusn db (njs 3 Int rob (vector & nums) ft int m= Nnums-sizeco -! 3 3 yetuun solve Tab Chums yn Jo 7 Te=0m) Dry yun a bums [2]@] 3] 2 J —_ ot 2 38 j __ (t(] + money eauned Coming up te im howe _ N= 3 __ We have te creat. dp pe 24 ea pS ata Ta] 022 2 -s IdpfoJ = 17 num Co) (Bane case) aa dp OJ =max (2,4) =2Q Y 7 o+dptop a O+ Mums liz 4 (2) = mance (1+3, 4) = 4 _ temp 7 7 Corapriy _— Tyre C2) ovuamicu win Gam Y Z Zemp Space ©, \:\) ay dpl3J =max C2 +], 04 4) = a C ophmigatien ou dp Ct) dependa en _dpli-!3 ond dpCi-2)- Hence we can Simply dewith the help 6, 3 —— x 4 ap l2] nue Cay nt Space Obt (vector &numis Ink nt : int preva =0 4 int brev| = Dumas [od + Int cus = O + for Cink Us 1s U4 sneint) £ CUM = 3 (ano Ske ne cee Tnt_ temp =° 3 Pare er | = a> Op CH) int extlude= Ot pveviy ma> “Cinclude , exclude) 3 / r dfdty 2 Apl-37 — p=prev2 2 fear emb+numa Ces ) wevl 5 BESKOKds)) — | x etusn prev ls ——————-= 5 3 eS Sc = OU) | lng breva = 0 9 prev) = SCE ‘uo wit Vain Classinate Date. Page | include = 2 exclude = 2 Us = ob veo breva-1 , prev! =2 temp = + include = 4 exclude = 2 Cun = 4 £23 prevdQ =2 , previ = 4 temp= =2 Include = 3 ee 4 Cunn = 4 Nour prevd= 4, eae meed te netunn 4 & hence we Scanned with Cam

You might also like