



下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、题目来源Ural 1611. Decimation题目描述读入一个n(0n=10000)位的 01 字符串,至多k 个 1,使得在 10 的倍数位上的 1 的个数最少。算法描述动态规划算法实现这道题目的方程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 的个数,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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 公司生产流程管理制度
- 光轨道角动量光子晶体光纤的设计及性能分析
- 2025授权经销合同范本
- 情感分析与拍卖平台用户体验优化-洞察阐释
- 2024年上海青浦教育系统招聘事业编制教师真题
- 神经内科帕金森病基础知识点归纳
- 2024年安康紫阳县特岗教师招聘真题
- 2025年四川轻化工大学数学竞赛试题
- 幼儿园保育工作相关表格与工作制度:实验幼儿园户外活动检查记录表
- 基于类间关系建模的异常区域分割算法研究
- 实习考勤表(完整版)
- 基础护理知识考核试题及答案
- 污水处理厂三级安全教育培训课件
- GB/T 97.4-2002平垫圈用于螺钉和垫圈组合件
- GB/T 8626-2007建筑材料可燃性试验方法
- GB/T 1222-2016弹簧钢
- GB 1886.187-2016食品安全国家标准食品添加剂山梨糖醇和山梨糖醇液
- 2023年济南市初中学生学业水平考试地理试题
- 几何公差与几何误差检测
- DB32-T 4273-2022 计算机辅助人工处方审核标准化工作规范
- DB44-T 2331-2021公路混凝土桥梁火灾后安全性能评定技术规程-(高清现行)
评论
0/150
提交评论