下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、題目來源Ural 1611. Decimation題目描述讀入一個n(0n=10000)位的 01 字符串,至多k 個 1,使得在 10 的倍數(shù)位上的 1 的個數(shù)最少。算法描述動態(tài)規(guī)劃算法實現(xiàn)這道題目的方程f(i,j)表示前i 位j 個字符的,分以下情況1 當 i+j mod 10=0 則 f(i,j):=max(f(i-1,j)+ord(sti)-48,f(i,j-1)+1)2 當i+j mod 100 則f(i,j):=max(f(i-1,j),f(i,j-1)表示的含義是:當i+j mod 10=0 則將該位置上的 1 的會增加中 1 的個數(shù),f(i-1,j)表示不1 的情況下。f(i,
2、j-1)表示原來的字串中在(i+j)的位置則不用考慮f(i,j-1);再從后往前掃描 如果ai,j=ai,j-1+1 表示在i+j 位置有位置輸出即可。一個 1。當j=0 時了一個 1,所源程序var n,k,i,j:long;ans:array1.50of long;a:array0.100000,0.50of long st:ansistring;beginreadln(n,k); readln(st);for i:=0 to k do a0,i:=i div 10; for i:=1 to n dofor j:=0 to k do beginif (i+j) mod 10=0)and(s
3、ti=1)then ai,j:=ai-1,j+1else ai,j:=ai-1,j; if j0 thenif (i+j) mod 10=0then begin if ai,jai,j-1+1 then ai,j:=ai,j-1+1 end else begin if ai,jai,j-1 then ai,j:=ai,j-1; end;end; j:=0;for i:=0 to kf an,jan,i then j:=i; i:=n;wrin(an,j); k:=0;while (i=0)and(j0) do if (i+j) mod 10=0then if ai,j=ai,j-1+1 the
4、n begin inc(k); ansk:=i+j; dec(j); end else dec(i) else if ai,j=ai,j-1 then begin inc(k); ansk:=i+j; dec(j); end else dec(i); write(k); for i:=k downto 1 do write( ,ansi);wrin;end.原題描述:1611. Decimation Time Limit: 0.5 second Memory Limit: 64 MBDecimation was a form of extreme military discipline use
5、d he Roman Army, when every tenth soldier was executed.Do you think fare dodgers fine without because theyit is easy to work as a conductor in a always try to ride free of charge, and remorse not only fare dodgers but also dont cope with their duties.tram? Persistent ticket inspectors tram conductor
6、she course of operation Fare Dodger 2008, which was carried out recently by the Yekaterinburg Assotion of Ticket Inspectors, itturned outt in every tram there waseast one fare dodger at the of Yekaterinburg becamemoment of inspection. Chief Ticket Inspectorfurious and decided to punish conductors. H
7、e a column and to fine every tenth conductor a conductors salary.ordered to line them up insum equalto aageChiere Dodger of Yekaterinburg felt sorry for poor decided to help them, because he knewt some of theconductors and conductors weregood Fare fare everyand coped with their duties. Before conduc
8、tors are fined, ChiefDodger can placeothe column some of his friends, who are alsododgers. Chief TicketInspector doesntthisand will fine10 (the number Dodger towhosenumberhehe column is a multiple ofof the place hiscolumn is 1). Help Chierefriendshe column sot the total numberof fined faredodgers an
9、d good conductors be minimal.InputThelinecontainsegers n (1 n 10000) andspace; they are the number of conductorsk (0 k 50)he columnseparated by a and the numberof Chiere Dodgers friends who are ready to help the line consists of n symbols; the ith symbol ishe column is initially occupied by a goodco
10、nductors. The second“1” if the ith placeconductor, and “0” if the conductor is bad.Outputhe and good dodgers which are separatedline, output the minimal total number of fined faredodgers re egers,he second line, output the number mconductors.t should be their numbers by a space.omplacedhe column, and then outputhe resulting column. The numbersmustbeSlesinput10 2output000000000
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 課件圖片沒了教學課件
- 2024年度知識產(chǎn)權(quán)許可合同補充協(xié)議
- 2024年太陽能路燈物流與倉儲服務(wù)合同
- 2024化工廠建設(shè)土石方運輸合同
- 04年新一代移動通信技術(shù)研發(fā)合同
- 2024年度企業(yè)招聘外包合同
- 2024規(guī)范版汽車租賃合同
- 課程課件封面教學課件
- 2024年國際貨物買賣合同標的數(shù)量與質(zhì)量檢驗標準詳解
- 2024學校校園廣告投放合同
- 2024年企業(yè)數(shù)據(jù)存儲與安全服務(wù)合同
- 2022年北京市公務(wù)員錄用考試《行測》真題及答案解析
- 江蘇省泰興市2024-2025學年高三上學期期中考試語文試題(含答案)
- 家長會教學課件
- 2024年消防宣傳月知識競賽考試題庫500題(含答案)
- 2024年典型事故案例警示教育手冊15例
- 高一歷史(中外歷史綱要上冊)期中測試卷及答案
- 20K607 防排煙及暖通防火設(shè)計審查與安裝
- 一氧化碳中毒培訓課件
- 教案(餐巾折花)
- 一元三次、一元四次方程的基本解法畢業(yè)論文
評論
0/150
提交評論