﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-wyh123-随笔分类-DP</title><link>http://www.cppblog.com/wyh123/category/17432.html</link><description>解题思路记录和牢骚</description><language>zh-cn</language><lastBuildDate>Thu, 17 May 2012 04:22:32 GMT</lastBuildDate><pubDate>Thu, 17 May 2012 04:22:32 GMT</pubDate><ttl>60</ttl><item><title>poj 1042（DP）</title><link>http://www.cppblog.com/wyh123/archive/2011/08/10/152984.html</link><dc:creator>wyh</dc:creator><author>wyh</author><pubDate>Wed, 10 Aug 2011 13:16:00 GMT</pubDate><guid>http://www.cppblog.com/wyh123/archive/2011/08/10/152984.html</guid><wfw:comment>http://www.cppblog.com/wyh123/comments/152984.html</wfw:comment><comments>http://www.cppblog.com/wyh123/archive/2011/08/10/152984.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wyh123/comments/commentRss/152984.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wyh123/services/trackbacks/152984.html</trackback:ping><description><![CDATA[题目大意：<span>john现有h个小时的空闲时间，他打算去钓鱼。john钓鱼的地方共有n个湖，所有的湖沿着一条单向路顺序排列（john每在一个湖钓完鱼后，他只能走到下一个湖继续钓），john必须从1号湖开始钓起，但是他可以在任何一个湖结束他此次钓鱼的行程。输入给出john在每个湖中每5分钟钓的鱼数（此题中以5分钟作为单位时间），随时间的增长而线性递减。而每个湖中头5分钟可以钓到的鱼数以及每个湖中相邻5分钟钓鱼数的减少量，John从任意一个湖走到它下一个湖的时间。 <br /><br />解题思路：1）设fish[i][j]表示到了第i个池塘用了j*5分钟所钓到的雨的数目<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2）转移：fish[i][j]=Max{fish[i-1][j-k-t[i]],fish[i][j]+sum}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum是呆着这个池塘经过k*5分钟所钓到的鱼的数目~sum=f[i]*(k+1)-(k+1)*k/2*d[i]<br /><br />代码： 
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstring</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstring</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cmath</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">algorithm</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">10</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;f[</span><span style="color: #000000">30</span><span style="color: #000000">],d[</span><span style="color: #000000">30</span><span style="color: #000000">],t[</span><span style="color: #000000">30</span><span style="color: #000000">],path[</span><span style="color: #000000">30</span><span style="color: #000000">];<br /></span><span style="color: #008080">11</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;fish[</span><span style="color: #000000">30</span><span style="color: #000000">][</span><span style="color: #000000">400</span><span style="color: #000000">];<br /></span><span style="color: #008080">12</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n,h,maxx,k;<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">14</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;init()<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img id="Codehighlighter1_217_288_Open_Image" onclick="this.style.display='none'; Codehighlighter1_217_288_Open_Text.style.display='none'; Codehighlighter1_217_288_Closed_Image.style.display='inline'; Codehighlighter1_217_288_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_217_288_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_217_288_Closed_Text.style.display='none'; Codehighlighter1_217_288_Open_Image.style.display='inline'; Codehighlighter1_217_288_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_217_288_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_217_288_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;memset(path,&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">,&nbsp;</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(path));<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;memset(fish,</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(fish));<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">19</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">20</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;find_Path(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;time)<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img id="Codehighlighter1_323_576_Open_Image" onclick="this.style.display='none'; Codehighlighter1_323_576_Open_Text.style.display='none'; Codehighlighter1_323_576_Closed_Image.style.display='inline'; Codehighlighter1_323_576_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_323_576_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_323_576_Closed_Text.style.display='none'; Codehighlighter1_323_576_Open_Image.style.display='inline'; Codehighlighter1_323_576_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_323_576_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_323_576_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(i</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">;<br /></span><span style="color: #008080">23</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;summ</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">24</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;k</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;k</span><span style="color: #000000">&lt;=</span><span style="color: #000000">12</span><span style="color: #000000">*</span><span style="color: #000000">h;&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">k)<br /></span><span style="color: #008080">25</span><span style="color: #000000"><img id="Codehighlighter1_385_574_Open_Image" onclick="this.style.display='none'; Codehighlighter1_385_574_Open_Text.style.display='none'; Codehighlighter1_385_574_Closed_Image.style.display='inline'; Codehighlighter1_385_574_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_385_574_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_385_574_Closed_Text.style.display='none'; Codehighlighter1_385_574_Open_Image.style.display='inline'; Codehighlighter1_385_574_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_385_574_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_385_574_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">26</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(fish[i</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">][time</span><span style="color: #000000">-</span><span style="color: #000000">k</span><span style="color: #000000">-</span><span style="color: #000000">t[i</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">]]</span><span style="color: #000000">+</span><span style="color: #000000">summ</span><span style="color: #000000">==</span><span style="color: #000000">fish[i][time])<br /></span><span style="color: #008080">27</span><span style="color: #000000"><img id="Codehighlighter1_440_500_Open_Image" onclick="this.style.display='none'; Codehighlighter1_440_500_Open_Text.style.display='none'; Codehighlighter1_440_500_Closed_Image.style.display='inline'; Codehighlighter1_440_500_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_440_500_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_440_500_Closed_Text.style.display='none'; Codehighlighter1_440_500_Open_Image.style.display='inline'; Codehighlighter1_440_500_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_440_500_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_440_500_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">28</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path[i]</span><span style="color: #000000">=</span><span style="color: #000000">k</span><span style="color: #000000">*</span><span style="color: #000000">5</span><span style="color: #000000">;<br /></span><span style="color: #008080">29</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;find_Path(i</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">,time</span><span style="color: #000000">-</span><span style="color: #000000">k</span><span style="color: #000000">-</span><span style="color: #000000">t[i</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">]);<br /></span><span style="color: #008080">30</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">31</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(f[i]</span><span style="color: #000000">-</span><span style="color: #000000">k</span><span style="color: #000000">*</span><span style="color: #000000">d[i]</span><span style="color: #000000">&gt;</span><span style="color: #000000">0</span><span style="color: #000000">)<br /></span><span style="color: #008080">32</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;summ</span><span style="color: #000000">=</span><span style="color: #000000">f[i]</span><span style="color: #000000">*</span><span style="color: #000000">(k</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">)</span><span style="color: #000000">-</span><span style="color: #000000">(k</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">)</span><span style="color: #000000">*</span><span style="color: #000000">k</span><span style="color: #000000">/</span><span style="color: #000000">2</span><span style="color: #000000">*</span><span style="color: #000000">d[i];<br /></span><span style="color: #008080">33</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">34</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">35</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">36</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;get_DP()<br /></span><span style="color: #008080">37</span><span style="color: #000000"><img id="Codehighlighter1_593_1233_Open_Image" onclick="this.style.display='none'; Codehighlighter1_593_1233_Open_Text.style.display='none'; Codehighlighter1_593_1233_Closed_Image.style.display='inline'; Codehighlighter1_593_1233_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_593_1233_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_593_1233_Closed_Text.style.display='none'; Codehighlighter1_593_1233_Open_Image.style.display='inline'; Codehighlighter1_593_1233_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_593_1233_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_593_1233_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">38</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;fish[</span><span style="color: #000000">0</span><span style="color: #000000">][</span><span style="color: #000000">0</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">39</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">n</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">i)<br /></span><span style="color: #008080">40</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;j</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;j</span><span style="color: #000000">&lt;=</span><span style="color: #000000">12</span><span style="color: #000000">*</span><span style="color: #000000">h;&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">j)<br /></span><span style="color: #008080">41</span><span style="color: #000000"><img id="Codehighlighter1_668_1046_Open_Image" onclick="this.style.display='none'; Codehighlighter1_668_1046_Open_Text.style.display='none'; Codehighlighter1_668_1046_Closed_Image.style.display='inline'; Codehighlighter1_668_1046_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_668_1046_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_668_1046_Closed_Text.style.display='none'; Codehighlighter1_668_1046_Open_Image.style.display='inline'; Codehighlighter1_668_1046_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_668_1046_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_668_1046_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">42</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;summ</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">43</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;k</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;k</span><span style="color: #000000">&lt;=</span><span style="color: #000000">12</span><span style="color: #000000">*</span><span style="color: #000000">h&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;fish[i][j]</span><span style="color: #000000">!=-</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">k)<br /></span><span style="color: #008080">44</span><span style="color: #000000"><img id="Codehighlighter1_763_1036_Open_Image" onclick="this.style.display='none'; Codehighlighter1_763_1036_Open_Text.style.display='none'; Codehighlighter1_763_1036_Closed_Image.style.display='inline'; Codehighlighter1_763_1036_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_763_1036_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_763_1036_Closed_Text.style.display='none'; Codehighlighter1_763_1036_Open_Image.style.display='inline'; Codehighlighter1_763_1036_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_763_1036_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_763_1036_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">45</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(j</span><span style="color: #000000">+</span><span style="color: #000000">k</span><span style="color: #000000">+</span><span style="color: #000000">t[i]</span><span style="color: #000000">&lt;=</span><span style="color: #000000">12</span><span style="color: #000000">*</span><span style="color: #000000">h)<br /></span><span style="color: #008080">46</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fish[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">][j</span><span style="color: #000000">+</span><span style="color: #000000">k</span><span style="color: #000000">+</span><span style="color: #000000">t[i]]</span><span style="color: #000000">=</span><span style="color: #000000">max(fish[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">][j</span><span style="color: #000000">+</span><span style="color: #000000">k</span><span style="color: #000000">+</span><span style="color: #000000">t[i]],fish[i][j]</span><span style="color: #000000">+</span><span style="color: #000000">summ);<br /></span><span style="color: #008080">47</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /></span><span style="color: #008080">48</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /></span><span style="color: #008080">49</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(f[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">]</span><span style="color: #000000">-</span><span style="color: #000000">k</span><span style="color: #000000">*</span><span style="color: #000000">d[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">]</span><span style="color: #000000">&gt;</span><span style="color: #000000">0</span><span style="color: #000000">)<br /></span><span style="color: #008080">50</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;summ</span><span style="color: #000000">=</span><span style="color: #000000">f[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">]</span><span style="color: #000000">*</span><span style="color: #000000">(k</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">)</span><span style="color: #000000">-</span><span style="color: #000000">(k</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">)</span><span style="color: #000000">*</span><span style="color: #000000">k</span><span style="color: #000000">/</span><span style="color: #000000">2</span><span style="color: #000000">*</span><span style="color: #000000">d[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">];<br /></span><span style="color: #008080">51</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">52</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">53</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;maxx</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">54</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;k</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">55</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;n;&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">i)<br /></span><span style="color: #008080">56</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(maxx</span><span style="color: #000000">&lt;</span><span style="color: #000000">fish[i][</span><span style="color: #000000">12</span><span style="color: #000000">*</span><span style="color: #000000">h])<br /></span><span style="color: #008080">57</span><span style="color: #000000"><img id="Codehighlighter1_1160_1231_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1160_1231_Open_Text.style.display='none'; Codehighlighter1_1160_1231_Closed_Image.style.display='inline'; Codehighlighter1_1160_1231_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1160_1231_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1160_1231_Closed_Text.style.display='none'; Codehighlighter1_1160_1231_Open_Image.style.display='inline'; Codehighlighter1_1160_1231_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1160_1231_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1160_1231_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">58</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;maxx</span><span style="color: #000000">=</span><span style="color: #000000">fish[i][</span><span style="color: #000000">12</span><span style="color: #000000">*</span><span style="color: #000000">h];<br /></span><span style="color: #008080">59</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;k</span><span style="color: #000000">=</span><span style="color: #000000">i;<br /></span><span style="color: #008080">60</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">61</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">62</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">63</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /></span><span style="color: #008080">64</span><span style="color: #000000"><img id="Codehighlighter1_1247_1767_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1247_1767_Open_Text.style.display='none'; Codehighlighter1_1247_1767_Closed_Image.style.display='inline'; Codehighlighter1_1247_1767_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_1247_1767_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1247_1767_Closed_Text.style.display='none'; Codehighlighter1_1247_1767_Open_Image.style.display='inline'; Codehighlighter1_1247_1767_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1247_1767_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1247_1767_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">65</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">&nbsp;(</span><span style="color: #000000">~</span><span style="color: #000000">scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">n))<br /></span><span style="color: #008080">66</span><span style="color: #000000"><img id="Codehighlighter1_1281_1751_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1281_1751_Open_Text.style.display='none'; Codehighlighter1_1281_1751_Closed_Image.style.display='inline'; Codehighlighter1_1281_1751_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1281_1751_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1281_1751_Closed_Text.style.display='none'; Codehighlighter1_1281_1751_Open_Image.style.display='inline'; Codehighlighter1_1281_1751_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1281_1751_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1281_1751_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">67</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(n</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /></span><span style="color: #008080">68</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">h);<br /></span><span style="color: #008080">69</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">f[i]);<br /></span><span style="color: #008080">70</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">d[i]);<br /></span><span style="color: #008080">71</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">n</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">t[i]);<br /></span><span style="color: #008080">72</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;init();<br /></span><span style="color: #008080">73</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;get_DP();<br /></span><span style="color: #008080">74</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;find_Path(k,&nbsp;</span><span style="color: #000000">12</span><span style="color: #000000">*</span><span style="color: #000000">h);<br /></span><span style="color: #008080">75</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;n</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">i)<br /></span><span style="color: #008080">76</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,path[i]);<br /></span><span style="color: #008080">77</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\n</span><span style="color: #000000">"</span><span style="color: #000000">,path[n]);<br /></span><span style="color: #008080">78</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">Number&nbsp;of&nbsp;fish&nbsp;expected:&nbsp;%d\n</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;fish[k][</span><span style="color: #000000">12</span><span style="color: #000000">*</span><span style="color: #000000">h]);<br /></span><span style="color: #008080">79</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /></span><span style="color: #008080">80</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">81</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">82</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">83</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span></div><br /><br /><br /></span><img src ="http://www.cppblog.com/wyh123/aggbug/152984.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wyh123/" target="_blank">wyh</a> 2011-08-10 21:16 <a href="http://www.cppblog.com/wyh123/archive/2011/08/10/152984.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>poj 1036（DP）</title><link>http://www.cppblog.com/wyh123/archive/2011/08/09/152890.html</link><dc:creator>wyh</dc:creator><author>wyh</author><pubDate>Tue, 09 Aug 2011 12:40:00 GMT</pubDate><guid>http://www.cppblog.com/wyh123/archive/2011/08/09/152890.html</guid><wfw:comment>http://www.cppblog.com/wyh123/comments/152890.html</wfw:comment><comments>http://www.cppblog.com/wyh123/archive/2011/08/09/152890.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wyh123/comments/commentRss/152890.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wyh123/services/trackbacks/152890.html</trackback:ping><description><![CDATA[题目大意： 宾馆有个伸缩门，其开放状态用[0,k]之间某个数来表示，每秒钟它至多可以伸长或减少1个单位。现在有n个强盗，他们会在ti的时间到达宾馆，如果此时门的开放度和他的身材si恰好相同，他就会进来，并得到pi的加分。一开始门是关闭的(开放度为0)，请你求出时刻t的最大加分。<br /><br /><br />解题思路：1）这道题的状态很容易就可以找出来：dp[i][j]表示在第i秒钟门的宽度为j所取得的最大加分。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2）那么转移就是：dp[i][j]=Max{dp[i-1][j+1],dp[i-1][j-1],dp[i][j]}+dp[i][j]~前一个时刻可以由三个状态转变而来，直接求最大值就可以了<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3)&nbsp;这道题的空间限制是10000K~，完整的数组开不了，只能开滚动数组~（WA了之后才发现的）<br /><br />~~本以为改为滚动数组后就过了~~，没想到果断T了~~，没办法，又加了张hash记录强盗在什么时刻到达宾馆来稍微稍微降低复杂度。<br /><br /><br />代码：
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstring</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">string</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cmath</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">algorithm</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">10</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">struct</span><span style="color: #000000">&nbsp;Person<br /></span><span style="color: #008080">11</span><span style="color: #000000"><img id="Codehighlighter1_150_167_Open_Image" onclick="this.style.display='none'; Codehighlighter1_150_167_Open_Text.style.display='none'; Codehighlighter1_150_167_Closed_Image.style.display='inline'; Codehighlighter1_150_167_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_150_167_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_150_167_Closed_Text.style.display='none'; Codehighlighter1_150_167_Open_Image.style.display='inline'; Codehighlighter1_150_167_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_150_167_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_150_167_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">12</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;t,s,p;<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000">num[</span><span style="color: #000000">110</span><span style="color: #000000">];<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;dp[</span><span style="color: #000000">3</span><span style="color: #000000">][</span><span style="color: #000000">110</span><span style="color: #000000">];<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;hash[</span><span style="color: #000000">30100</span><span style="color: #000000">];<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n,t,k,summ;<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">18</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">19</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;init()<br /></span><span style="color: #008080">20</span><span style="color: #000000"><img id="Codehighlighter1_241_305_Open_Image" onclick="this.style.display='none'; Codehighlighter1_241_305_Open_Text.style.display='none'; Codehighlighter1_241_305_Closed_Image.style.display='inline'; Codehighlighter1_241_305_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_241_305_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_241_305_Closed_Text.style.display='none'; Codehighlighter1_241_305_Open_Image.style.display='inline'; Codehighlighter1_241_305_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_241_305_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_241_305_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;memset(dp,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(dp));<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;memset(hash,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(hash));<br /></span><span style="color: #008080">23</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">24</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">25</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;get_DP()<br /></span><span style="color: #008080">26</span><span style="color: #000000"><img id="Codehighlighter1_322_875_Open_Image" onclick="this.style.display='none'; Codehighlighter1_322_875_Open_Text.style.display='none'; Codehighlighter1_322_875_Closed_Image.style.display='inline'; Codehighlighter1_322_875_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_322_875_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_322_875_Closed_Text.style.display='none'; Codehighlighter1_322_875_Open_Image.style.display='inline'; Codehighlighter1_322_875_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_322_875_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_322_875_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">27</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">t;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">28</span><span style="color: #000000"><img id="Codehighlighter1_357_873_Open_Image" onclick="this.style.display='none'; Codehighlighter1_357_873_Open_Text.style.display='none'; Codehighlighter1_357_873_Closed_Image.style.display='inline'; Codehighlighter1_357_873_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_357_873_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_357_873_Closed_Text.style.display='none'; Codehighlighter1_357_873_Open_Image.style.display='inline'; Codehighlighter1_357_873_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_357_873_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_357_873_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">29</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;j</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;j</span><span style="color: #000000">&lt;=</span><span style="color: #000000">k&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;j</span><span style="color: #000000">&lt;=</span><span style="color: #000000">i;&nbsp;j</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">30</span><span style="color: #000000"><img id="Codehighlighter1_408_867_Open_Image" onclick="this.style.display='none'; Codehighlighter1_408_867_Open_Text.style.display='none'; Codehighlighter1_408_867_Closed_Image.style.display='inline'; Codehighlighter1_408_867_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_408_867_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_408_867_Closed_Text.style.display='none'; Codehighlighter1_408_867_Open_Image.style.display='inline'; Codehighlighter1_408_867_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_408_867_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_408_867_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">31</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;summ</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">32</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(hash[i]</span><span style="color: #000000">!=</span><span style="color: #000000">0</span><span style="color: #000000">)<br /></span><span style="color: #008080">33</span><span style="color: #000000"><img id="Codehighlighter1_470_592_Open_Image" onclick="this.style.display='none'; Codehighlighter1_470_592_Open_Text.style.display='none'; Codehighlighter1_470_592_Closed_Image.style.display='inline'; Codehighlighter1_470_592_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_470_592_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_470_592_Closed_Text.style.display='none'; Codehighlighter1_470_592_Open_Image.style.display='inline'; Codehighlighter1_470_592_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_470_592_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_470_592_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">34</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;l</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;l</span><span style="color: #000000">&lt;</span><span style="color: #000000">n;&nbsp;l</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">35</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(i</span><span style="color: #000000">==</span><span style="color: #000000">num[l].t&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;j</span><span style="color: #000000">==</span><span style="color: #000000">num[l].s)&nbsp;summ</span><span style="color: #000000">+=</span><span style="color: #000000">num[l].p;<br /></span><span style="color: #008080">36</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">37</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(j</span><span style="color: #000000">==</span><span style="color: #000000">k)&nbsp;dp[i</span><span style="color: #000000">%</span><span style="color: #000000">3</span><span style="color: #000000">][j]</span><span style="color: #000000">=</span><span style="color: #000000">max(dp[(i</span><span style="color: #000000">+</span><span style="color: #000000">2</span><span style="color: #000000">)</span><span style="color: #000000">%</span><span style="color: #000000">3</span><span style="color: #000000">][j</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">],dp[(i</span><span style="color: #000000">+</span><span style="color: #000000">2</span><span style="color: #000000">)</span><span style="color: #000000">%</span><span style="color: #000000">3</span><span style="color: #000000">][j]);<br /></span><span style="color: #008080">38</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(j</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)&nbsp;dp[i</span><span style="color: #000000">%</span><span style="color: #000000">3</span><span style="color: #000000">][j]</span><span style="color: #000000">=</span><span style="color: #000000">max(dp[(i</span><span style="color: #000000">+</span><span style="color: #000000">2</span><span style="color: #000000">)</span><span style="color: #000000">%</span><span style="color: #000000">3</span><span style="color: #000000">][j</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">],dp[(i</span><span style="color: #000000">+</span><span style="color: #000000">2</span><span style="color: #000000">)</span><span style="color: #000000">%</span><span style="color: #000000">3</span><span style="color: #000000">][j]);<br /></span><span style="color: #008080">39</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;dp[i</span><span style="color: #000000">%</span><span style="color: #000000">3</span><span style="color: #000000">][j]</span><span style="color: #000000">=</span><span style="color: #000000">max(max(dp[(i</span><span style="color: #000000">+</span><span style="color: #000000">2</span><span style="color: #000000">)</span><span style="color: #000000">%</span><span style="color: #000000">3</span><span style="color: #000000">][j</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">],dp[(i</span><span style="color: #000000">+</span><span style="color: #000000">2</span><span style="color: #000000">)</span><span style="color: #000000">%</span><span style="color: #000000">3</span><span style="color: #000000">][j]),dp[(i</span><span style="color: #000000">+</span><span style="color: #000000">2</span><span style="color: #000000">)</span><span style="color: #000000">%</span><span style="color: #000000">3</span><span style="color: #000000">][j</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">]);<br /></span><span style="color: #008080">40</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp[i</span><span style="color: #000000">%</span><span style="color: #000000">3</span><span style="color: #000000">][j]</span><span style="color: #000000">+=</span><span style="color: #000000">summ;<br /></span><span style="color: #008080">41</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">42</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">43</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">44</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">45</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;cmp(</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;Person&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">a,</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;Person&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">b)<br /></span><span style="color: #008080">46</span><span style="color: #000000"><img id="Codehighlighter1_919_976_Open_Image" onclick="this.style.display='none'; Codehighlighter1_919_976_Open_Text.style.display='none'; Codehighlighter1_919_976_Closed_Image.style.display='inline'; Codehighlighter1_919_976_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_919_976_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_919_976_Closed_Text.style.display='none'; Codehighlighter1_919_976_Open_Image.style.display='inline'; Codehighlighter1_919_976_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_919_976_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_919_976_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">47</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(a.t</span><span style="color: #000000">==</span><span style="color: #000000">b.t)&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;a.s</span><span style="color: #000000">&lt;</span><span style="color: #000000">b.s;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;a.t</span><span style="color: #000000">&lt;</span><span style="color: #000000">b.t;<br /></span><span style="color: #008080">48</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">49</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">50</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /></span><span style="color: #008080">51</span><span style="color: #000000"><img id="Codehighlighter1_990_1441_Open_Image" onclick="this.style.display='none'; Codehighlighter1_990_1441_Open_Text.style.display='none'; Codehighlighter1_990_1441_Closed_Image.style.display='inline'; Codehighlighter1_990_1441_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_990_1441_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_990_1441_Closed_Text.style.display='none'; Codehighlighter1_990_1441_Open_Image.style.display='inline'; Codehighlighter1_990_1441_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_990_1441_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_990_1441_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">52</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d%d%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">n,</span><span style="color: #000000">&amp;</span><span style="color: #000000">k,</span><span style="color: #000000">&amp;</span><span style="color: #000000">t);<br /></span><span style="color: #008080">53</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /></span><span style="color: #008080">54</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">55</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">(num[i].t));<br /></span><span style="color: #008080">56</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">57</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">(num[i].p));<br /></span><span style="color: #008080">58</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">59</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">(num[i].s));<br /></span><span style="color: #008080">60</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;sort(num,num</span><span style="color: #000000">+</span><span style="color: #000000">n,cmp);<br /></span><span style="color: #008080">61</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;init();<br /></span><span style="color: #008080">62</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">63</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hash[num[i].t]</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">64</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;get_DP();<br /></span><span style="color: #008080">65</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;maxx</span><span style="color: #000000">=-</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">66</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">k;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">67</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(maxx</span><span style="color: #000000">&lt;</span><span style="color: #000000">dp[t</span><span style="color: #000000">%</span><span style="color: #000000">3</span><span style="color: #000000">][i])&nbsp;&nbsp;maxx</span><span style="color: #000000">=</span><span style="color: #000000">dp[t</span><span style="color: #000000">%</span><span style="color: #000000">3</span><span style="color: #000000">][i];<br /></span><span style="color: #008080">68</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,maxx);<br /></span><span style="color: #008080">69</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">70</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">71</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span></div><br /><img src ="http://www.cppblog.com/wyh123/aggbug/152890.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wyh123/" target="_blank">wyh</a> 2011-08-09 20:40 <a href="http://www.cppblog.com/wyh123/archive/2011/08/09/152890.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>poj 1015（DP）</title><link>http://www.cppblog.com/wyh123/archive/2011/08/09/152857.html</link><dc:creator>wyh</dc:creator><author>wyh</author><pubDate>Tue, 09 Aug 2011 06:47:00 GMT</pubDate><guid>http://www.cppblog.com/wyh123/archive/2011/08/09/152857.html</guid><wfw:comment>http://www.cppblog.com/wyh123/comments/152857.html</wfw:comment><comments>http://www.cppblog.com/wyh123/archive/2011/08/09/152857.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wyh123/comments/commentRss/152857.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wyh123/services/trackbacks/152857.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 题目大意：&nbsp;在遥远的国家佛罗布尼亚，嫌犯是否有罪，须由陪审团决定。陪审团是由法官从公众中挑选的。先随机挑选n 个人作为陪审团的候选人，然后再从这n 个人中选m 人组成陪审团。选m 人的办法是：控方和辩方会根据对候选人的喜欢程度，给所有候选人打分，分值从0 到20。为了公平起见，法官选出陪审团的原则是：选出的m 个人，必须满足辩方总分和控方总分的差的绝对值最小。如果有多种选择方案的辩方总分...&nbsp;&nbsp;<a href='http://www.cppblog.com/wyh123/archive/2011/08/09/152857.html'>阅读全文</a><img src ="http://www.cppblog.com/wyh123/aggbug/152857.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wyh123/" target="_blank">wyh</a> 2011-08-09 14:47 <a href="http://www.cppblog.com/wyh123/archive/2011/08/09/152857.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDOJ 1176（DP）</title><link>http://www.cppblog.com/wyh123/archive/2011/08/03/152338.html</link><dc:creator>wyh</dc:creator><author>wyh</author><pubDate>Wed, 03 Aug 2011 04:08:00 GMT</pubDate><guid>http://www.cppblog.com/wyh123/archive/2011/08/03/152338.html</guid><wfw:comment>http://www.cppblog.com/wyh123/comments/152338.html</wfw:comment><comments>http://www.cppblog.com/wyh123/archive/2011/08/03/152338.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wyh123/comments/commentRss/152338.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wyh123/services/trackbacks/152338.html</trackback:ping><description><![CDATA[题目大意：<br />
<div class="panel_content">都说天上不会掉馅饼，但有一天gameboy正走在回家的小径上，忽然天上掉下大把大把的馅饼。说来gameboy的人品实在是太好了，这馅饼别处都不掉，就掉落在他身旁的10米范围内。馅饼如果掉在了地上当然就不能吃了，所以gameboy马上卸下身上的背包去接。但由于小径两侧都不能站人，所以他只能在小径上接。由于gameboy平时老呆在房间里玩游戏，虽然在游戏中是个身手敏捷的高手，但在现实中运动神经特别迟钝，每秒种只有在移动不超过一米的范围内接住坠落的馅饼。现在给这条小径如图标上坐标：<br />
<center><img src="http://acm.hdu.edu.cn/data/images/1176_1.jpg"  alt="" /></center><br />为了使问题简化，假设在接下来的一段时间里，馅饼都掉落在0-10这11个位置。开始时gameboy站在5这个位置，因此在第一秒，他只能接到4,5,6这三个位置中其中一个位置上的馅饼。问gameboy最多可能接到多少个馅饼？（假设他的背包可以容纳无穷多个馅饼）<br /></div><br /><br />解题思路：1）由题目可以知道，在某个时间点在某点接住馅饼，则前一个时间点必须在这个点的左边，右边或者就在这个点。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2）根据题设，我们不妨设dp[i][j]为在第i秒在j处接住的馅饼。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 则有：&nbsp;&nbsp;&nbsp; dp[i][j]=Max{dp[i-1][j-1],dp[i-1][j],dp[i-1][j+1]}+a[i][j];<br /><br /><br />代码
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cmath</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">algorithm</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstring</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a[</span><span style="color: #000000">100010</span><span style="color: #000000">][</span><span style="color: #000000">15</span><span style="color: #000000">];<br /></span><span style="color: #008080">10</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;dp[</span><span style="color: #000000">100010</span><span style="color: #000000">][</span><span style="color: #000000">15</span><span style="color: #000000">];<br /></span><span style="color: #008080">11</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;t,n,p,q,maxx;<br /></span><span style="color: #008080">12</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">13</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img id="Codehighlighter1_187_1165_Open_Image" onclick="this.style.display='none'; Codehighlighter1_187_1165_Open_Text.style.display='none'; Codehighlighter1_187_1165_Closed_Image.style.display='inline'; Codehighlighter1_187_1165_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_187_1165_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_187_1165_Closed_Text.style.display='none'; Codehighlighter1_187_1165_Open_Image.style.display='inline'; Codehighlighter1_187_1165_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_187_1165_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_187_1165_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">&nbsp;(</span><span style="color: #000000">~</span><span style="color: #000000">scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">n))<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img id="Codehighlighter1_221_1149_Open_Image" onclick="this.style.display='none'; Codehighlighter1_221_1149_Open_Text.style.display='none'; Codehighlighter1_221_1149_Closed_Image.style.display='inline'; Codehighlighter1_221_1149_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_221_1149_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_221_1149_Closed_Text.style.display='none'; Codehighlighter1_221_1149_Open_Image.style.display='inline'; Codehighlighter1_221_1149_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_221_1149_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_221_1149_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(n</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t</span><span style="color: #000000">=-</span><span style="color: #000000">(</span><span style="color: #000000">1</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">30</span><span style="color: #000000">);<br /></span><span style="color: #008080">19</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(a,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(a));<br /></span><span style="color: #008080">20</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(dp,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(dp));<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img id="Codehighlighter1_375_469_Open_Image" onclick="this.style.display='none'; Codehighlighter1_375_469_Open_Text.style.display='none'; Codehighlighter1_375_469_Closed_Image.style.display='inline'; Codehighlighter1_375_469_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_375_469_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_375_469_Closed_Text.style.display='none'; Codehighlighter1_375_469_Open_Image.style.display='inline'; Codehighlighter1_375_469_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_375_469_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_375_469_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">23</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;p&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;q;<br /></span><span style="color: #008080">24</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[q][p]</span><span style="color: #000000">++</span><span style="color: #000000">;<br /></span><span style="color: #008080">25</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(t</span><span style="color: #000000">&lt;</span><span style="color: #000000">q)&nbsp;t</span><span style="color: #000000">=</span><span style="color: #000000">q;<br /></span><span style="color: #008080">26</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">27</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp[</span><span style="color: #000000">1</span><span style="color: #000000">][</span><span style="color: #000000">5</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">a[</span><span style="color: #000000">1</span><span style="color: #000000">][</span><span style="color: #000000">5</span><span style="color: #000000">];<br /></span><span style="color: #008080">28</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp[</span><span style="color: #000000">1</span><span style="color: #000000">][</span><span style="color: #000000">6</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">a[</span><span style="color: #000000">1</span><span style="color: #000000">][</span><span style="color: #000000">6</span><span style="color: #000000">];<br /></span><span style="color: #008080">29</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp[</span><span style="color: #000000">1</span><span style="color: #000000">][</span><span style="color: #000000">4</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">a[</span><span style="color: #000000">1</span><span style="color: #000000">][</span><span style="color: #000000">4</span><span style="color: #000000">];<br /></span><span style="color: #008080">30</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">t</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">31</span><span style="color: #000000"><img id="Codehighlighter1_592_1011_Open_Image" onclick="this.style.display='none'; Codehighlighter1_592_1011_Open_Text.style.display='none'; Codehighlighter1_592_1011_Closed_Image.style.display='inline'; Codehighlighter1_592_1011_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_592_1011_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_592_1011_Closed_Text.style.display='none'; Codehighlighter1_592_1011_Open_Image.style.display='inline'; Codehighlighter1_592_1011_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_592_1011_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_592_1011_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">32</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;j</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;j</span><span style="color: #000000">&lt;=</span><span style="color: #000000">10</span><span style="color: #000000">;&nbsp;j</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">33</span><span style="color: #000000"><img id="Codehighlighter1_646_1001_Open_Image" onclick="this.style.display='none'; Codehighlighter1_646_1001_Open_Text.style.display='none'; Codehighlighter1_646_1001_Closed_Image.style.display='inline'; Codehighlighter1_646_1001_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_646_1001_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_646_1001_Closed_Text.style.display='none'; Codehighlighter1_646_1001_Open_Image.style.display='inline'; Codehighlighter1_646_1001_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_646_1001_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_646_1001_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">34</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(dp[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">][j</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">]</span><span style="color: #000000">&lt;</span><span style="color: #000000">a[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">][j</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">]</span><span style="color: #000000">+</span><span style="color: #000000">dp[i][j]&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;j</span><span style="color: #000000">&lt;</span><span style="color: #000000">10</span><span style="color: #000000">)<br /></span><span style="color: #008080">35</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">][j</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">dp[i][j]</span><span style="color: #000000">+</span><span style="color: #000000">a[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">][j</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">];<br /></span><span style="color: #008080">36</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(dp[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">][j]</span><span style="color: #000000">&lt;</span><span style="color: #000000">a[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">][j]</span><span style="color: #000000">+</span><span style="color: #000000">dp[i][j])<br /></span><span style="color: #008080">37</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">][j]</span><span style="color: #000000">=</span><span style="color: #000000">dp[i][j]</span><span style="color: #000000">+</span><span style="color: #000000">a[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">][j];<br /></span><span style="color: #008080">38</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(dp[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">][j</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">]</span><span style="color: #000000">&lt;</span><span style="color: #000000">a[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">][j</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">]</span><span style="color: #000000">+</span><span style="color: #000000">dp[i][j]&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;j</span><span style="color: #000000">&gt;</span><span style="color: #000000">0</span><span style="color: #000000">)<br /></span><span style="color: #008080">39</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">][j</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">dp[i][j]</span><span style="color: #000000">+</span><span style="color: #000000">a[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">][j</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">];<br /></span><span style="color: #008080">40</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">41</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">42</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;maxx</span><span style="color: #000000">=-</span><span style="color: #000000">(</span><span style="color: #000000">1</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">30</span><span style="color: #000000">);<br /></span><span style="color: #008080">43</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">11</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">44</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(dp[t][i]</span><span style="color: #000000">&gt;</span><span style="color: #000000">maxx)&nbsp;maxx</span><span style="color: #000000">=</span><span style="color: #000000">dp[t][i];<br /></span><span style="color: #008080">45</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;maxx&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;<br /></span><span style="color: #008080">46</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">47</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">48</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">49</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span></div>：<br /><img src ="http://www.cppblog.com/wyh123/aggbug/152338.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wyh123/" target="_blank">wyh</a> 2011-08-03 12:08 <a href="http://www.cppblog.com/wyh123/archive/2011/08/03/152338.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDOJ 2041(DP)</title><link>http://www.cppblog.com/wyh123/archive/2011/07/31/152131.html</link><dc:creator>wyh</dc:creator><author>wyh</author><pubDate>Sun, 31 Jul 2011 02:58:00 GMT</pubDate><guid>http://www.cppblog.com/wyh123/archive/2011/07/31/152131.html</guid><wfw:comment>http://www.cppblog.com/wyh123/comments/152131.html</wfw:comment><comments>http://www.cppblog.com/wyh123/archive/2011/07/31/152131.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wyh123/comments/commentRss/152131.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wyh123/services/trackbacks/152131.html</trackback:ping><description><![CDATA[题目大意：有一楼梯共M级，刚开始时你在第一级，若每次只能跨上一级或二级，要走上第M级，共有多少种走法？<br /><br />解题思路：用dp[i]表示走到第i级的方法数。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 那么走到第i级的最后一步只可能是两种，走一级或者两级，即dp[i]=dp[i-1]+dp[i-2]<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 注意，开始的时候是在第一级开始的，所以要求的是dp[n-1]<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;写完之后才发现它是斐波那契数列啊~~囧~！！！<br /><br />代码：<br />
<p>&nbsp;</p>
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cmath</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;sum[</span><span style="color: #000000">45</span><span style="color: #000000">];<br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;T,n;<br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">10</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /></span><span style="color: #008080">11</span><span style="color: #000000"><img id="Codehighlighter1_118_308_Open_Image" onclick="this.style.display='none'; Codehighlighter1_118_308_Open_Text.style.display='none'; Codehighlighter1_118_308_Closed_Image.style.display='inline'; Codehighlighter1_118_308_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_118_308_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_118_308_Closed_Text.style.display='none'; Codehighlighter1_118_308_Open_Image.style.display='inline'; Codehighlighter1_118_308_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_118_308_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_118_308_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;&nbsp;sum[</span><span style="color: #000000">1</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">12</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;sum[</span><span style="color: #000000">2</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">2</span><span style="color: #000000">;<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">3</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">40</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum[i]</span><span style="color: #000000">=</span><span style="color: #000000">sum[i</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">]</span><span style="color: #000000">+</span><span style="color: #000000">sum[i</span><span style="color: #000000">-</span><span style="color: #000000">2</span><span style="color: #000000">];<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;T;<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">&nbsp;(T</span><span style="color: #000000">--</span><span style="color: #000000">)<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img id="Codehighlighter1_242_292_Open_Image" onclick="this.style.display='none'; Codehighlighter1_242_292_Open_Text.style.display='none'; Codehighlighter1_242_292_Closed_Image.style.display='inline'; Codehighlighter1_242_292_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_242_292_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_242_292_Closed_Text.style.display='none'; Codehighlighter1_242_292_Open_Image.style.display='inline'; Codehighlighter1_242_292_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_242_292_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_242_292_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;n;<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;sum[n</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;<br /></span><span style="color: #008080">19</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">20</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">22</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span></div>
<p>&nbsp;</p>  <img src ="http://www.cppblog.com/wyh123/aggbug/152131.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wyh123/" target="_blank">wyh</a> 2011-07-31 10:58 <a href="http://www.cppblog.com/wyh123/archive/2011/07/31/152131.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDOJ 2067(DP)</title><link>http://www.cppblog.com/wyh123/archive/2011/07/31/152128.html</link><dc:creator>wyh</dc:creator><author>wyh</author><pubDate>Sun, 31 Jul 2011 02:29:00 GMT</pubDate><guid>http://www.cppblog.com/wyh123/archive/2011/07/31/152128.html</guid><wfw:comment>http://www.cppblog.com/wyh123/comments/152128.html</wfw:comment><comments>http://www.cppblog.com/wyh123/archive/2011/07/31/152128.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/wyh123/comments/commentRss/152128.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wyh123/services/trackbacks/152128.html</trackback:ping><description><![CDATA[<div>题目大意：小兔的叔叔从外面旅游回来给她带来了一个礼物，小兔高兴地跑回自己的房间，拆开一看是一个棋盘，小兔有所失望。不过没过几天发现了棋盘的好玩之处。从起点(0，0)走到终点(n,n)的最短路径数是C(2n,n),现在小兔又想如果不穿越对角线(但可接触对角线上的格点)，这样的路径数有多少?<br /><br />解题思路：很明显的DP，dp[i][j]表示走到(i,j)的路径数。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 转移方程：dp[i][j]=dp[i-1][j]+dp[i][j-1](i!=j);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dp[i][j]=0(i=j);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这里面要注意的是这里的(0,0)表示的是格子，而方程里面的(i,j)表示的是下格点<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;所以事实上(n,n)换成格子表示是(n+1,n+1)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 而所有的对角线上的格点也是来源于其左边和上面的格点所以ans=dp[n+1][n]+dp[n][n+1]<br /><br /><br />代码：
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstring</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cmath</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;m,n,k;<br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;dp[</span><span style="color: #000000">40</span><span style="color: #000000">][</span><span style="color: #000000">40</span><span style="color: #000000">];<br /></span><span style="color: #008080">10</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">11</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /></span><span style="color: #008080">12</span><span style="color: #000000"><img id="Codehighlighter1_142_555_Open_Image" onclick="this.style.display='none'; Codehighlighter1_142_555_Open_Text.style.display='none'; Codehighlighter1_142_555_Closed_Image.style.display='inline'; Codehighlighter1_142_555_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_142_555_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_142_555_Closed_Text.style.display='none'; Codehighlighter1_142_555_Open_Image.style.display='inline'; Codehighlighter1_142_555_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_142_555_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_142_555_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;&nbsp;dp[</span><span style="color: #000000">0</span><span style="color: #000000">][</span><span style="color: #000000">0</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">37</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img id="Codehighlighter1_194_226_Open_Image" onclick="this.style.display='none'; Codehighlighter1_194_226_Open_Text.style.display='none'; Codehighlighter1_194_226_Closed_Image.style.display='inline'; Codehighlighter1_194_226_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_194_226_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_194_226_Closed_Text.style.display='none'; Codehighlighter1_194_226_Open_Image.style.display='inline'; Codehighlighter1_194_226_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_194_226_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_194_226_Open_Text"><span style="color: #000000">{&nbsp;dp[</span><span style="color: #000000">0</span><span style="color: #000000">][i]</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;dp[i][</span><span style="color: #000000">0</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">16</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">37</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;j</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;j</span><span style="color: #000000">&lt;=</span><span style="color: #000000">37</span><span style="color: #000000">;&nbsp;j</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(i&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;j)<br /></span><span style="color: #008080">19</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp[i][j]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;dp[i</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">][j]&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;dp[i][j</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">];<br /></span><span style="color: #008080">20</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /></span><span style="color: #008080">21</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /></span><span style="color: #008080">22</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp[i][j]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">23</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;k</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">24</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;n)<br /></span><span style="color: #008080">25</span><span style="color: #000000"><img id="Codehighlighter1_450_538_Open_Image" onclick="this.style.display='none'; Codehighlighter1_450_538_Open_Text.style.display='none'; Codehighlighter1_450_538_Closed_Image.style.display='inline'; Codehighlighter1_450_538_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_450_538_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_450_538_Closed_Text.style.display='none'; Codehighlighter1_450_538_Open_Image.style.display='inline'; Codehighlighter1_450_538_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_450_538_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_450_538_Open_Text"><span style="color: #000000">{</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(n</span><span style="color: #000000">==-</span><span style="color: #000000">1</span><span style="color: #000000">)&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /></span><span style="color: #008080">26</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">k&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">n</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">dp[n</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">][n]</span><span style="color: #000000">+</span><span style="color: #000000">dp[n][n</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;&nbsp;k</span><span style="color: #000000">++</span><span style="color: #000000">;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">27</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /></span><span style="color: #008080">28</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">29</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">30</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span></div><br /><br />其实勒，这道题是由于数据量比较小，所以可以使用DP+long long来解决，但是其本质上还是属于一个排列组合问题，如果数据量变大的话，需要用到大数来解决。<br /><br /></div><img src ="http://www.cppblog.com/wyh123/aggbug/152128.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wyh123/" target="_blank">wyh</a> 2011-07-31 10:29 <a href="http://www.cppblog.com/wyh123/archive/2011/07/31/152128.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDOJ 1267(DP)</title><link>http://www.cppblog.com/wyh123/archive/2011/07/31/152104.html</link><dc:creator>wyh</dc:creator><author>wyh</author><pubDate>Sat, 30 Jul 2011 16:15:00 GMT</pubDate><guid>http://www.cppblog.com/wyh123/archive/2011/07/31/152104.html</guid><wfw:comment>http://www.cppblog.com/wyh123/comments/152104.html</wfw:comment><comments>http://www.cppblog.com/wyh123/archive/2011/07/31/152104.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wyh123/comments/commentRss/152104.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wyh123/services/trackbacks/152104.html</trackback:ping><description><![CDATA[题目描述：给出m个H和n个D，求由这m个H和n个D组成的字符串满足&#8220;从左到右扫描该串，字符H的累计数总是不小于字符D的累计数&#8221;的方案数<br /><br /><br />解题思路：DP<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 显然，这里面可以把状态划分为dp[i][j]，表示i个H和n个D含有多少成功的方案数。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 那么它的转移方程就是： dp[i][j]=dp[i-1][j]+dp[i][j-1];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1）所有的串一定是以H或者D结尾<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3）i&gt;j,则dp[i][j]=0;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3）在成功的dp[i-1][j]后面中加上H，则这个是必然成立的。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4）关键是在成功的dp[i][j-1]后面中加上D。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如果此时恰好是i=j-1的话，加上D就错了~~，但问题是当i=j-1的时候i&lt;j的根本不满足2)，所以这个无须考虑的。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;那么这里只有可能是i&gt;j-1，所以加上了D，最坏的情况就是i=j，不会出现不满足题意的情况。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5）有人会认为可以通过一个不成功的串可以通过向其中加上一个H使其满足题设：<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Eg：HDD+H=HDHD<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;这里给的反例是HDH+D=HDHD<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 其实很简单，HDD和HDH所出现的概率是相等的，所以一个不成功的串其中插入H势必会找到一个相对应的成功的串后面加上D<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *写的时候也是凭感觉写出来，一做发现对了。后来才仔细的想了一下，其实转移也算是比较别扭的，不过总的来说这不是一道很难的DP题。<br /><br /><br />代码： 
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstring</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cmath</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /><br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /><br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;m,n;<br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;dp[</span><span style="color: #000000">50</span><span style="color: #000000">][</span><span style="color: #000000">50</span><span style="color: #000000">];<br /></span><span style="color: #008080">10</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /><br /></span><span style="color: #008080">11</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /></span><span style="color: #008080">12</span><span style="color: #000000"><img id="Codehighlighter1_140_449_Open_Image" onclick="this.style.display='none'; Codehighlighter1_140_449_Open_Text.style.display='none'; Codehighlighter1_140_449_Closed_Image.style.display='inline'; Codehighlighter1_140_449_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_140_449_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_140_449_Closed_Text.style.display='none'; Codehighlighter1_140_449_Open_Image.style.display='inline'; Codehighlighter1_140_449_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_140_449_Closed_Text"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_140_449_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">20</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp[i][</span><span style="color: #000000">1</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;i;<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">2</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">20</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;j</span><span style="color: #000000">=</span><span style="color: #000000">2</span><span style="color: #000000">;&nbsp;j</span><span style="color: #000000">&lt;=</span><span style="color: #000000">20</span><span style="color: #000000">;&nbsp;j</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(i&nbsp;</span><span style="color: #000000">&gt;=</span><span style="color: #000000">&nbsp;j)<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp[i][j]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;dp[i][j</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;dp[i</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">][j];<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /></span><span style="color: #008080">19</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp[i][j]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">20</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;m&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;n)<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;dp[m][n]&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" /><br /></span><span style="color: #008080">23</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">24</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">25</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span></div><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <img src ="http://www.cppblog.com/wyh123/aggbug/152104.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wyh123/" target="_blank">wyh</a> 2011-07-31 00:15 <a href="http://www.cppblog.com/wyh123/archive/2011/07/31/152104.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>