Asit'sthefirstofApril,Heidiissuspectingthatthenewsshereadstodayarefake,andshedoesnotwanttolooksillyinfrontofallthecontestants.Sheknowsthatanewspieceisfakeifitcontainsheidiasasubsequence.HelpHeidiassesswhetherthegivenpieceistrue,butpleasebediscreetaboutit...
Thefirstandonlylineofinputcontainsasinglenonemptystringsoflengthatmost1000composedoflowercaseletters(a-z).
OutputYESifthestringscontainsheidiasasubsequenceandNOotherwise.
abcheaibcdioutputYESinputhiedioutputNONoteAstringscontainsanotherstringpasasubsequenceifitispossibletodeletesomecharactersfromsandobtainp.
看下给你的字符串是否存在“heidi”
#include
HoweverI,Heidi,willhavenoneofthat.Asmyjokefortoday,Iamremovingthestoryfromthestatementandreplacingitwiththesetwounhelpfulparagraphs.Nowsolvetheproblem,fools!
Thefirstlineoftheinputcontainstwospace-separatedintegersnandk(1≤k≤n≤2200).Thesecondlinecontainsnspace-separatedintegersa1,...,an(1≤ai≤104).
Outputonenumber.
8511111111output5input1031682451225632128641output7input512010503046output10input66666666output36input11100output100我在做这些水题真的好么?只当练英语了,n个数选k个最小的和,不开心的时候就A水题?#include Heidi'sfriendJennyisaskingHeiditodeliveranimportantlettertooneoftheircommonfriends.SinceJennyisIrish,Heidithinksthatthismightbeaprank.Moreprecisely,shesuspectsthatthemessagesheisaskedtodeliverstates:"Sendthefoolfurther!",anduponreadingittherecipientwillaskHeiditodeliverthesamemessagetoyetanotherfriend(thattherecipienthasincommonwithHeidi),andsoon. Heidibelievesthatherfriendswanttoavoidawkwardsituations,soshewillnotbemadetovisitthesameperson(includingJenny)twice.Shealsoknowshowmuchitcoststotravelbetweenanytwoofherfriendswhoknoweachother.Shewantstoknow:whatisthemaximalamountofmoneyshewillwasteontravelifitreallyisaprank Heidi'snfriendsarelabeled0throughn-1,andtheirnetworkofconnectionsformsatree.Inotherwords,everytwoofherfriendsa,bknoweachother,possiblyindirectly(thereisasequenceoffriendsstartingfromaandendingonbandsuchthateachtwoconsecutivefriendsinthesequenceknoweachotherdirectly),andthereareexactlyn-1pairsoffriendswhoknoweachotherdirectly. Jennyisgiventhenumber0. Thefirstlineoftheinputcontainsthenumberoffriendsn(3≤n≤100).Thenextn-1lineseachcontainthreespace-separatedintegersu,vandc(0≤u,v≤n-1,1≤c≤104),meaningthatuandvarefriends(knoweachotherdirectly)andthecostfortravellingbetweenuandvisc. Itisguaranteedthatthesocialnetworkoftheinputformsatree. Outputasingleinteger–themaximumsumofcosts. 4014022233output5input6123021001420373510output105input1110166420881324670421555511870621265722888722669215361063378output5551NoteInthesecondexample,theworst-casescenariogoeslikethis:JennysendsHeiditothefriendlabeledbynumber2(incurringacostof100),thenfriend2sendshertofriend1(costingHeidi3),andfinallyfriend1relayshertofriend4(incurringanadditionalcostof2). 就是简单的DFS一遍,找到从根到叶的最长路,这个自己当然是想不出来的,别人的代码真的很巧妙 #include YoursearchforHeidiisover–youfinallyfoundheratalibrary,dressedupasahuman.Infact,shehasspentsomuchtimetherethatshenowrunstheplace!Herjobistobuybooksandkeepthematthelibrarysothatpeoplecanborrowandreadthem.Therearendifferentbooks,numbered1throughn. Wewilllookatthelibrary'soperationduringnconsecutivedays.Heidiknowsinadvancethatonthei-thday(1≤i≤n)preciselyonepersonwillcometothelibrary,requesttoborrowthebookai,readitinafewhours,andreturnthebooklateronthesameday. Heididesperatelywantstopleaseallherguests,soshewillmakesuretoalwayshavethebookaiavailableinthelibraryonthei-thday.Duringthenightbeforethei-thday,shehastheoptionofgoingtothebookstore(whichoperatesatnightstoavoidcompetitionwiththelibrary)andbuyinganybookforthepriceof1CHF.Ofcourse,ifshealreadyhasabookatthelibrary,shedoesnotneedtobuyitagain.Initially,thelibrarycontainsnobooks. Thereisaproblem,though.Thecapacityofthelibraryisk–thismeansthatatanytime,therecanbeatmostkbooksatthelibrary.IfbuyinganewbookwouldcauseHeiditohavemorethankbooks,shemustfirstgetridofsomebookthatshealreadyhas,inordertomakeroomforthenewbook.Ifshelaterneedsabookthatshegotridof,shewillneedtobuythatbookagain. Youaregivenkandthesequenceofrequestsforbooksa1,a2,...,an.Whatistheminimumcost(inCHF)ofbuyingnewbookstosatisfyalltherequests Thefirstlineofinputwillcontaintwointegersnandk(1≤n,k≤80).Thesecondlinewillcontainnintegersa1,a2,...,an(1≤ai≤n)–thesequenceofbookrequests. Onasinglelineprinttheminimumcostofbuyingbooksatthestoresoastosatisfyallrequests. 4801221output2input411221output3input421231output3NoteInthefirsttestcase,Heidiisabletokeepallbooksforever.Therefore,sheonlyneedstobuythebook1beforethefirstdayandthebook2beforethesecondday. Inthesecondtestcase,shecanonlykeeponebookatatime.Thereforeshewillneedtobuynewbooksonthefirst,secondandfourthday. Inthethirdtestcase,beforebuyingbook3onthethirdday,shemustdecidewhichofthebooks1and2sheshouldgetridof.Ofcourse,sheshouldkeepthebook1,whichwillberequestedonthefourthday. Q巨和我们讲这个是页面置换算法,其中最完美的是OPT,但是好像硬件并没有这样实现 举例如下: #include