Hdoj 5303 Delicious Apples Enumeration +DP
Last Update:2015-07-24
Source: Internet
Author: User
<span id="Label3"></p><p><p><br></p></p><p><p><span style="font-size:18px">Enumeration +DP</span><br></p></p><p><p><span style="font-size:18px">Although on the ring, but the most around the ring walk once</span></p></p><p><p><span style="font-size:18px">dp[0][i] The first I point all counter-clockwise to take out,</span> <span style="font-size:18px">dp[1][i] from I to n clockwise finish</span></p></p><p><p><span style="font-size:18px">Then enumerate the middle dividing line, and from which point start to turn a circle</span></p></p><p><p><span style="font-size:18px"><br></span></p></p><p><p></p></p>Delicious Apples<span style="font-family:‘Times New Roman‘; font-size:14px">time <span style="font-family:‘Times New Roman‘; font-size:14px"> <strong> <span style="font-family:Arial; font-size:12px; color:green">limit:5000/3000 MS (java/others) Memory limit:524288/524288 K (java/others)<br>Total Submission (s): 734 Accepted submission (s): 240<br></span></strong></span></span><br style="font-family:‘Times New Roman‘; font-size:14px"><br style="font-family:‘Times New Roman‘; font-size:14px">Problem Descriptionthere is<span class="MathJax_Preview" style="color:rgb(136,136,136)"><span class="MathJax_Preview" style="color:rgb(136,136,136)"></span></span><span class="MathJax" id="MathJax-Element-1-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"><span class="MathJax" id="MathJax-Element-1-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"> <nobr style=""> <span class="math" id="MathJax-Span-1" style=""> <span style=""><span style=""> <span class="mrow" id="MathJax-Span-2" style=""><span class="mi" id="MathJax-Span-3" style=""></span></span> n <span style=""><span style=""></span></span> </span></span> </span> </nobr> </span></span>Apple trees planted along a cyclic road, which is<span class="MathJax_Preview" style="color:rgb(136,136,136)"><span class="MathJax_Preview" style="color:rgb(136,136,136)"></span></span><span class="MathJax" id="MathJax-Element-2-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"><span class="MathJax" id="MathJax-Element-2-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"> <nobr style=""> <span class="math" id="MathJax-Span-4" style=""> <span style=""><span style=""> <span class="mrow" id="MathJax-Span-5" style=""><span class="mi" id="MathJax-Span-6" style=""></span></span> L <span style=""><span style=""></span></span> </span></span> </span> </nobr> </span></span>metres long. Your Storehouse is built at position<span class="MathJax_Preview" style="color:rgb(136,136,136)"><span class="MathJax_Preview" style="color:rgb(136,136,136)"></span></span><span class="MathJax" id="MathJax-Element-3-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"><span class="MathJax" id="MathJax-Element-3-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"> <nobr style=""> <span class="math" id="MathJax-Span-7" style=""> <span style=""><span style=""> <span class="mrow" id="MathJax-Span-8" style=""><span class="mn" id="MathJax-Span-9" style=""></span></span> 0 <span style=""><span style=""></span></span> </span></span> </span> </nobr> </span></span>On that cyclic road.<br>The<span class="MathJax_Preview" style="color:rgb(136,136,136)"><span class="MathJax_Preview" style="color:rgb(136,136,136)"></span></span><span class="MathJax" id="MathJax-Element-4-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"><span class="MathJax" id="MathJax-Element-4-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"> <nobr style=""> <span class="math" id="MathJax-Span-10" style=""> <span style=""><span style=""> <span class="mrow" id="MathJax-Span-11" style=""><span class="mi" id="MathJax-Span-12" style=""></span></span> i <span style=""><span style=""></span></span> </span></span> </span> </nobr> </span></span>Th tree is planted at position<span class="MathJax_Preview" style="color:rgb(136,136,136)"><span class="MathJax_Preview" style="color:rgb(136,136,136)"></span></span><span class="MathJax" id="MathJax-Element-5-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"><span class="mathjax" id="mathjax-element-5-frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px "> <nobr style=" "> <span class=" math " id=" mathjax-span-13 " style=" "><span style=" "><span style=" ">< Span class= "mrow" id= "mathjax-span-14" style= "" ><span class="mi" id="mathjax-span-15" style="">x </span> <span class="msubsup" id="mathjax-span-16" style=""><span style=""><span style=""><span class="texatom" id="MathJax-Span-17" style=""><span class="mrow" id="mathjax-span-18" style=""><span class="mo" id="mathjax-span-19" style=""><span style=""> </span> </span> </span> </span> <span style=""> </span> </span> <span style=""><span class="mi" id="mathjax-span-20" style=""> I </span> <span style=""> </span> </span> </span> </span> </span> <span style=""> </span> </span> </span> <span style=""> </span> </nobr></span> <nobr style=" "> </nobr></span>, clockwise from position<span class="MathJax_Preview" style="color:rgb(136,136,136)"><span class="MathJax_Preview" style="color:rgb(136,136,136)"></span></span><span class="MathJax" id="MathJax-Element-6-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"><span class="MathJax" id="MathJax-Element-6-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"> <nobr style=""> <span class="math" id="MathJax-Span-21" style=""> <span style=""><span style=""> <span class="mrow" id="MathJax-Span-22" style=""><span class="mn" id="MathJax-Span-23" style=""></span></span> 0 <span style=""><span style=""></span></span> </span></span> </span> </nobr> </span></span>. There is<span class="MathJax_Preview" style="color:rgb(136,136,136)"><span class="MathJax_Preview" style="color:rgb(136,136,136)"></span></span><span class="MathJax" id="MathJax-Element-7-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"><span class="MathJax" id="MathJax-Element-7-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"> <nobr style=""> <span class="math" id="MathJax-Span-24" style=""> <span style=""><span style=""> <span class="mrow" id="MathJax-Span-25" style=""><span class="msubsup" id="MathJax-Span-26" style=""><span style=""> <span style=""> <span class="mi" id="MathJax-Span-27" style=""></span>a<span style=""><span style=""></span></span></span><span class="mi" id="MathJax-Span-28" style=""></span> i <span style=""><span style=""><span style=""></span></span></span> </span></span></span> </span></span> </span> </nobr> </span></span>Delicious Apple (s) on the<span class="MathJax_Preview" style="color:rgb(136,136,136)"><span class="MathJax_Preview" style="color:rgb(136,136,136)"></span></span><span class="MathJax" id="MathJax-Element-8-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"><span class="MathJax" id="MathJax-Element-8-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"> <nobr style=""> <span class="math" id="MathJax-Span-29" style=""> <span style=""><span style=""> <span class="mrow" id="MathJax-Span-30" style=""><span class="mi" id="MathJax-Span-31" style=""></span></span> i <span style=""><span style=""></span></span> </span></span> </span> </nobr> </span></span>Th tree.<br><br>You are only having a basket which can contain at the most<span class="MathJax_Preview" style="color:rgb(136,136,136)"><span class="MathJax_Preview" style="color:rgb(136,136,136)"></span></span><span class="MathJax" id="MathJax-Element-9-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"><span class="MathJax" id="MathJax-Element-9-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"> <nobr style=""> <span class="math" id="MathJax-Span-32" style=""> <span style=""><span style=""> <span class="mrow" id="MathJax-Span-33" style=""><span class="mi" id="MathJax-Span-34" style="">K <span style=""><span style=""><span style=""></span></span></span> </span></span> </span></span> </span> </nobr> </span></span>Apple (s). You is to start from your storehouse, pick all the apples and carry them back to your storehouse using your basket. What is your minimum distance travelled?<br><br><span class="MathJax_Preview" style="color:rgb(136,136,136)"><span class="MathJax_Preview" style="color:rgb(136,136,136)"></span></span><span class="MathJax" id="MathJax-Element-10-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"> <nobr style=""> <span class="math" id="MathJax-Span-35" style=""><span style=""><span style=""><span class="mrow" id="MathJax-Span-36" style=""><span class="mn" id="MathJax-Span-37" style=""><span class="mn" id="MathJax-Span-37" style="">1</span></span><span class="mo" id="MathJax-Span-38" style=""><span class="mo" id="MathJax-Span-38" style="">≤</span></span><span class="mi" id="MathJax-Span-39" style=""><span class="mi" id="MathJax-Span-39" style="">N</span></span><span class="mo" id="MathJax-Span-40" style=""><span class="mo" id="MathJax-Span-40" style="">,</span></span><span class="mi" id="MathJax-Span-41" style=""><span class="mi" id="MathJax-Span-41" style="">k</span></span><span class="mo" id="MathJax-Span-42" style=""><span class="mo" id="MathJax-Span-42" style="">≤</span></span><span class="msubsup" id="MathJax-Span-43" style=""><span class="msubsup" id="MathJax-Span-43" style=""><span style=""> <span style=""> <span class="mn" id="MathJax-Span-44" style=""></span>ten<span style=""><span style=""></span></span></span> <span style=""></span> <span class="mn" id="MathJax-Span-45" style="">5</span> </span></span></span><span class="mo" id="MathJax-Span-46" style=""><span class="mo" id="MathJax-Span-46" style="">,</span></span><span class="msubsup" id="MathJax-Span-47" style=""><span class="msubsup" id="MathJax-Span-47" style=""><span style=""> <span style=""> <span class="mi" id="MathJax-Span-48" style=""></span>a<span style=""><span style=""></span></span></span> <span style=""></span> <span class="mi" id="MathJax-Span-49" style="">i</span> </span></span></span><span class="mo" id="MathJax-Span-50" style=""><span class="mo" id="MathJax-Span-50" style="">≥</span></span><span class="mn" id="MathJax-Span-51" style=""><span class="mn" id="MathJax-Span-51" style="">1</span></span><span class="mo" id="MathJax-Span-52" style=""><span class="mo" id="MathJax-Span-52" style="">,</span></span><span class="msubsup" id="MathJax-Span-53" style=""><span class="msubsup" id="MathJax-Span-53" style=""><span style=""> <span style=""> <span class="mi" id="MathJax-Span-54" style=""></span>a<span style=""><span style=""></span></span></span> <span style=""></span> <span class="mn" id="MathJax-Span-55" style="">1</span> </span></span></span><span class="mo" id="MathJax-Span-56" style=""><span class="mo" id="MathJax-Span-56" style="">+</span></span><span class="msubsup" id="MathJax-Span-57" style=""><span class="msubsup" id="MathJax-Span-57" style=""><span style=""> <span style=""> <span class="mi" id="MathJax-Span-58" style=""></span>a<span style=""><span style=""></span></span></span> <span style=""></span> <span class="mn" id="MathJax-Span-59" style="">2</span> </span></span></span><span class="mo" id="MathJax-Span-60" style=""><span class="mo" id="MathJax-Span-60" style="">+</span></span><span class="mo" id="MathJax-Span-61" style=""><span class="mo" id="MathJax-Span-61" style="">.</span></span><span class="mo" id="MathJax-Span-62" style=""><span class="mo" id="MathJax-Span-62" style="">.</span></span><span class="mo" id="MathJax-Span-63" style=""><span class="mo" id="MathJax-Span-63" style="">.</span></span><span class="mo" id="MathJax-Span-64" style=""><span class="mo" id="MathJax-Span-64" style="">+</span></span><span class="msubsup" id="MathJax-Span-65" style=""><span class="msubsup" id="MathJax-Span-65" style=""><span style=""> <span style=""> <span class="mi" id="MathJax-Span-66" style=""></span>a<span style=""><span style=""></span></span></span> <span style=""></span> <span class="mi" id="MathJax-Span-67" style="">n</span> </span></span></span><span class="mo" id="MathJax-Span-68" style=""><span class="mo" id="MathJax-Span-68" style="">≤</span></span><span class="msubsup" id="MathJax-Span-69" style=""><span class="msubsup" id="MathJax-Span-69" style=""><span style=""> <span style=""> <span class="mn" id="MathJax-Span-70" style=""></span>ten<span style=""><span style=""></span></span></span> <span style=""></span> <span class="mn" id="MathJax-Span-71" style="">5</span> </span></span></span></span><span style=""><span style=""></span></span></span></span><span style=""><span style=""></span></span></span> </nobr></span><br><span class="MathJax_Preview" style="color:rgb(136,136,136)"><span class="mathjax_preview" style="color:rgb (136,136,136)"> </span> </span><span class="MathJax" id="MathJax-Element-11-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"><span class="mathjax" id="mathjax-element-11-frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px "> <nobr style=" "> <span class=" math " id=" mathjax-span-72 " style=" "><span style=" "><span style=" ">< Span class= "mrow" id= "mathjax-span-73" style= "" ><span class="mn" id="mathjax-span-74" style="">1 </span> <span class="mo" id="mathjax-span-75" style="">≤ </span> <span class="mi" id="mathjax-span-76" style="">l </span> <span class=" Mo " id=" mathjax-span-77 " style=" ">≤ </span> <span class=" msubsup " id=" mathjax-span-78 " style=" "><span style=" ">< Span style= "" ><span class="mn" id="mathjax-span-79" style="">10 </span> <span style=""> </span> </span> <span style=""><span class="mn" id="mathjax-span-80" style="">9 </span> <span style=""> </span> </span> </span> </span> </span> <span style=""> </span> </span> </nobr></span> <nobr style=" "> <span style=""> </span> </nobr> </span><br><span class="MathJax_Preview" style="color:rgb(136,136,136)"><span class="MathJax_Preview" style="color:rgb(136,136,136)"></span></span><span class="MathJax" id="MathJax-Element-12-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"><span class="MathJax" id="MathJax-Element-12-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"> <nobr style=""> <span class="math" id="MathJax-Span-81" style=""> <span style=""><span style=""> <span class="mrow" id="MathJax-Span-82" style=""> <span class="mn" id="MathJax-Span-83" style="">0</span><span class="mo" id="MathJax-Span-84" style="">≤</span><span class="mi" id="MathJax-Span-85" style="">x</span><span class="mo" id="MathJax-Span-86" style="">[</span><span class="mi" id="MathJax-Span-87" style="">i</span><span class="mo" id="MathJax-Span-88" style="">]</span><span class="mo" id="MathJax-Span-89" style="">≤</span><span class="mi" id="MathJax-Span-90" style="">L</span> </span> <span style=""><span style=""> </span></span></span></span></span> </nobr> </span></span><br><br>There is less than-huge testcases, and less than, small testcases.<br><br style="font-family:‘Times New Roman‘; font-size:14px">Inputfirst line:<span class="MathJax_Preview" style="color:rgb(136,136,136)"><span class="MathJax_Preview" style="color:rgb(136,136,136)"></span></span><span class="MathJax" id="MathJax-Element-13-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"><span class="MathJax" id="MathJax-Element-13-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"> <nobr style=""> <span class="math" id="MathJax-Span-91" style=""> <span style=""><span style=""> <span class="mrow" id="MathJax-Span-92" style=""><span class="mi" id="MathJax-Span-93" style=""></span></span> t <span style=""><span style=""></span></span> </span></span> </span> </nobr> </span></span>The number of Testcases.<br>Then<span class="MathJax_Preview" style="color:rgb(136,136,136)"><span class="MathJax_Preview" style="color:rgb(136,136,136)"></span></span><span class="MathJax" id="MathJax-Element-14-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"><span class="MathJax" id="MathJax-Element-14-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"> <nobr style=""> <span class="math" id="MathJax-Span-94" style=""> <span style=""><span style=""> <span class="mrow" id="MathJax-Span-95" style=""><span class="mi" id="MathJax-Span-96" style=""></span></span> t <span style=""><span style=""></span></span> </span></span> </span> </nobr> </span></span>Testcases FOLLOW. In each testcase:<br>First line contains three integers,<span class="MathJax_Preview" style="color:rgb(136,136,136)"><span class="MathJax_Preview" style="color:rgb(136,136,136)"></span></span><span class="MathJax" id="MathJax-Element-15-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"><span class="MathJax" id="MathJax-Element-15-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"> <nobr style=""> <span class="math" id="MathJax-Span-97" style=""> <span style=""><span style=""> <span class="mrow" id="MathJax-Span-98" style=""> <span class="mi" id="MathJax-Span-99" style="">L</span><span class="mo" id="MathJax-Span-100" style="">,</span><span class="mi" id="MathJax-Span-101" style="">n</span><span class="mo" id="MathJax-Span-102" style="">,</span><span class="mi" id="MathJax-Span-103" style="">K <span style=""><span style=""><span style=""></span></span></span> </span> </span> </span></span> </span> </nobr> </span></span>.<br>Next<span class="MathJax_Preview" style="color:rgb(136,136,136)"><span class="MathJax_Preview" style="color:rgb(136,136,136)"></span></span><span class="MathJax" id="MathJax-Element-16-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"><span class="MathJax" id="MathJax-Element-16-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"> <nobr style=""> <span class="math" id="MathJax-Span-104" style=""> <span style=""><span style=""> <span class="mrow" id="MathJax-Span-105" style=""><span class="mi" id="MathJax-Span-106" style=""></span></span> n <span style=""><span style=""></span></span> </span></span> </span> </nobr> </span></span>lines, each line contains<span class="MathJax_Preview" style="color:rgb(136,136,136)"><span class="MathJax_Preview" style="color:rgb(136,136,136)"></span></span><span class="MathJax" id="MathJax-Element-17-Frame" style="display:inline; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; direction:ltr; max-width:none; max-height:none; min-width:0px; min-height:0px; border:0px; padding:0px; margin:0px"> <nobr style=""> <nobr style=""> <span class="math" id="MathJax-Span-107" style=""> <span style=""><span style=""> <span class="mrow" id="MathJax-Span-108" style=""> <span class="msubsup" id="MathJax-Span-109" style=""><span style=""> <span style=""> <span class="mi" id="MathJax-Span-110" style=""></span>x<span style=""><span style=""></span></span></span><span class="mi" id="MathJax-Span-111" style=""></span>i<span style=""></span></span></span><span class="mo" id="MathJax-Span-112" style="">,</span><span class="msubsup" id="MathJax-Span-113" style=""><span style=""><span style=""><span class="mi" id="MathJax-Span-114" style="">a</span> <span style=""><span style=""></span></span> </span> <span class="mi" id="MathJax-Span-115" style=""></span> i <span style=""><span style=""><span style=""></span></span></span> </span></span> </span> </span></span> </span> </nobr> </nobr></span>.<br style="font-family:‘Times New Roman‘; font-size:14px">Outputoutput total distance in a line for each testcase.<br style="font-family:‘Times New Roman‘; font-size:14px">Sample Input<pre style="word-wrap:break-word; white-space:pre-wrap; margin-top:0px; margin-bottom:0px"><pre style="word-wrap:break-word; white-space:pre-wrap; margin-top:0px; margin-bottom:0px">210 3 22 28 25 110 4 12 28 25 10 10000</pre></pre><br style="font-family:‘Times New Roman‘; font-size:14px">Sample Output<pre style="word-wrap:break-word; white-space:pre-wrap; margin-top:0px; margin-bottom:0px"><pre style="word-wrap:break-word; white-space:pre-wrap; margin-top:0px; margin-bottom:0px">1826</pre></pre><br style="font-family:‘Times New Roman‘; font-size:14px">Source2015 multi-university Training Contest 2<br style="font-family:‘Times New Roman‘; font-size:14px">Recommendwange2014 | We have carefully selected several similar problems for you:5309 5307 5306 5304 5302<br><pre name="code" class="cpp">/* ***********************************************author:ckbosscreated time:2015 July 24 Friday 16:13 36 seconds file Name : hdoj5303.cpp************************************************ * * #include <iostream> #include <cstdio># Include <cstring> #include <algorithm> #include <string> #include <cmath> #include <cstdlib > #include <vector> #include <queue> #include <set> #include <map>using namespace Std;typedef Long long int ll;const int maxn=100100;struct apple{int pos,val;bool operator< (const apple& Apple) const{return Pos <apple.pos;}} Apple[maxn];int l,m,k,n; LL dist[maxn]; LL dp[2][maxn];int main () {//freopen ("in.txt", "r", stdin); Freopen ("out.txt", "w", stdout), int t_t;scanf ("%d", &t_t), while (t_t--) {memset (dist,0,sizeof (dist)); memset (DP , 0,sizeof (dp)), scanf ("%d%d%d", &l,&m,&k), for (int i=0,x,y;i<m;i++) {scanf ("%d%d", &x,&y); apple[i]= (Apple) {x, y};} N=1;sort (apple,apple+m); for (int i=0,x,y;i<m;i++) {x=apple[i].pos;y=apple[i].val;if (x==0| | X==l) continue;while (y--) dist[n++]=x;} For (int I=1;i<n;i++) {dp[0][i]=dp[0][max (0,i-k)]+dist[i]*2;} For (int i=n-1;i>0;i--) {dp[1][i]=dp[1][min (n+1,i+k)]+ (l-dist[i]) * *;} LL ans=min (dp[0][n-1],dp[1][1]); for (int i=1;i<n;i++) {ans=min (ans,dp[0][i]+dp[1][i+1]); ans=min (ans,dp[0][max (0 , i-k)]+dp[1][i+1]+l);} cout<<ans<<endl;} Return 0;}</pre><br><br><p><p></p></p> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article for Bo Master original article, without Bo Master permission not Reproduced.</p></p> <p><p>Hdoj 5303 Delicious Apples Enumeration +DP</p></p></span>