Givethemostefficientalgorithmyoucanfindtodeterminatwhichgasstationsyoushouldstopsothatthenumberoftimeyoustopisminimized,andprovethatyourstrategyyieldsanoptimalsolution.Besuretogivethetimecomplexityofyouralgorithmrespectton.
4.LinearProgramming
Anexpresscompanyneedstodelivergoodstoitsfiveusers.Thecompanywantstoupload1,2,3,4and8unitsofgoodsatfiveuserswhoseuserIDare1,2,3,4and5respectively.Thecompanyhaxatotaloffourtrucks,andthetrucks1to4havealoadof2,6,8and11units.ThecostoftruckidispatchingonceisCi.Duetodeliverytimerestrictions,onetruckcanneitherdelivergoodstoboothusersAandCattheasametime,nordelivergoodstobothBandDatthesametime.Pleasegiveadeliveringplantominimizethecost.
(1)Formulatethisproblemasanintergerlinearprogrammingproblemandexplaineveryvariableandconstraints.
(2)IftruckichargestheusersjfortheadditionalchargeKij,thenhowshouldtheproblembeformulated?
Notece:
Absolutevalue(|*|)shallneverappearinaLinearProgramming(LP)formulation,sinceitisnotalinearoperation.Nerthershallothernon-linearoperations,suchasmax(),etc.Ifyouwanttouseyourownnotation,Pleaseexplainitfirst.
5.NetworkFlow
Givennnumbers[a1,a2...an],numberscanbenegativeorpositive.
Youcanperformthefollowingoperationanynumberoftimes(possiblezero)
·Selectapositiveintergerxiassign0toALLaisatisfiediisdivisiblebyx.(ax=0,a2x=0,a3x=0...)
Byoptimallyperformingtheoperation,whatisthemaximumsumofNnumberscanbeobtained?
(Exanple,6numbers[1,2,-6,4,5,3],answeris12).
6.SubarraySum
Giveranarrayofpositiveintergersandanintergerk,
1.Pleasefindwhethertherearetwonumbersinthearraysuchthattheyadduptok,andthetimecomplexityofyouralgorithmshouldbebetterthanO(n2);
2.Pleasefindwhetherthereisacontinuoussubarraywhosesumequalstok,andthetimecomplexityofyouralgorithmshouldbebetterthanO(n2);
3.Pleasefindwhetherthereisasubsequence(Notnecessarilycontinuous)whosesumequalstok;
4.Pleaseconstructaarrayofshortestlengththatthesetofsumsofallsubsequencescoversalltheintergersbeteweenlandk.
Examplethatifk=4,theshortestarraycanbe[1,2,3]becausethatsumofsubsequence[1]equals1,sumofsubsequence[2]equals2,sumofsubsequence[1,2]queals3,andsumofsubsequence[1,3]equals4.Thesubsequencesumscancoverintergersfrom1to4.
7.Granph
Youaregivenanundiretedweighredgraphconsistingofnverticesandmedgeas,eachofedgeshasaweight.Youarealsogiventwoverticessandtinthegraph.
Forexample,agraphGconsistinfof6verticesand7edgeswithdifferentweightsisshownmsistheverticelabelled0andtistheverticelabelled5.
1.PleasefindwhetherthereisapathfromstotthatthemaximumweightofedgesinthepathisatmostW.Examplethatgivenω=6inG,thepath0->1->4->5issatisfiedbecausethemaximumedgeweightis5(1->4).
2.YouneedtofindapathfromstotthatthemaximumweightWofedgesinthepathisminimized.PleasecalculatettheminimumvalueofW.
Examplethatthereare3pathsfromstotinG:
0->1->3->5,0->1->4->5and0->2->4->5,themaximumedgeweightsinthesepathsis10,5and7,sotheminimumvalueofWis5.
3.Pleasefindtheshortestpathfromstotandthepathgoesthroughatmostkpoints(Notincludingsandt).