付費下載
下載本文檔
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
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)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- GB/T 16177-2025公共航空運輸旅客服務質量
- 【初中語文】《短文兩篇+愛蓮說》課件++統(tǒng)編版語文七年級下冊
- 汽車文化課件 第六章 未來汽車 第三節(jié) 清潔能源汽車
- 【寒假復習】人教版六年級數(shù)學上冊分數(shù)應用題專項訓練(含答案)
- 連云港市2026屆高三(一模)語文試卷(含答案)
- 化工儀表設計培訓課件
- 化工儀表培訓課件
- 2026北京中鋁資本控股有限公司校園招聘2人備考考試試題及答案解析
- 2026年蚌埠高新(自貿區(qū))醫(yī)院公開招聘工作人員招聘28名參考考試題庫及答案解析
- 2026上半年云南省水利廳部分直屬事業(yè)單位招聘32人備考考試試題及答案解析
- GB/T 19839-2025工業(yè)燃油燃氣燃燒器通用技術條件
- 銀行資產池管理辦法
- 人音版七年級音樂上冊說課稿:2.4 藍色的探戈
- 武漢大學人民醫(yī)院心理援助熱線崗位招聘3人考試參考題庫附答案解析
- 2025職業(yè)暴露處理流程及應急預案
- 知道智慧樹商業(yè)倫理與企業(yè)社會責任(山東財經(jīng)大學)滿分測試答案
- 六年級語文上冊《1-8單元》課本重點句子附仿寫示范
- 2025中國鐵路濟南局集團有限公司招聘普通高校本科及以上學歷畢業(yè)筆試參考題庫附帶答案詳解(10套)
- 外場工地施工管理辦法
- 國家中醫(yī)藥管理局《中醫(yī)藥事業(yè)發(fā)展“十五五”規(guī)劃》全文
- 全屋智能銷售培訓
評論
0/150
提交評論