算法2018考试.docx

上传人:b****0 文档编号:6863 上传时间:2022-09-30 格式:DOCX 页数:2 大小:85.80KB
下载 相关 举报
算法2018考试.docx_第1页
第1页 / 共2页
算法2018考试.docx_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

算法2018考试.docx

《算法2018考试.docx》由会员分享,可在线阅读,更多相关《算法2018考试.docx(2页珍藏版)》请在冰豆网上搜索。

算法2018考试.docx

1.DivideandConquer(14)

GivenabinarytreeT,pleasegiveanO(n)algorithmtoinvertbinarytree.

Forexamplebelow,invertingtheleftbinarytree,wegettherightbinarytree.

2.DynamicProgramming

Giventwosequences,Findthelengthofthecommonsubsequense(LCS).

Note:

Asubsequenceisdifferentfromasubstring,fortheformerneedNOTbeconsecutiveoftheoriginalsequence.Forexample,for“ABCD”and“AEFC”,thelongestcommonsubesequenceis“AC”,andthelengthofitis2.

PleasedescribetheoptimalsubstructureandDPequation.

3.Greedy

SupposeyouweretodrivefromBeijingtoXizang.Withafullgastank,youcantravelatmostmkm.Andyouhaveamapthatgivesdistancesbetweengasstationsalongtheroute.Letd1

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).

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 图表模板

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1