﻿<?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++博客-编程之路，漫漫修远兮-文章分类-SGU</title><link>http://www.cppblog.com/master0503/category/8711.html</link><description>不須計較與安排 領取而今現在</description><language>zh-cn</language><lastBuildDate>Mon, 03 Nov 2008 19:41:07 GMT</lastBuildDate><pubDate>Mon, 03 Nov 2008 19:41:07 GMT</pubDate><ttl>60</ttl><item><title>SGU 104. Little shop of flowers </title><link>http://www.cppblog.com/master0503/articles/65840.html</link><dc:creator>幻浪天空领主</dc:creator><author>幻浪天空领主</author><pubDate>Mon, 03 Nov 2008 06:35:00 GMT</pubDate><guid>http://www.cppblog.com/master0503/articles/65840.html</guid><wfw:comment>http://www.cppblog.com/master0503/comments/65840.html</wfw:comment><comments>http://www.cppblog.com/master0503/articles/65840.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/master0503/comments/commentRss/65840.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/master0503/services/trackbacks/65840.html</trackback:ping><description><![CDATA[<table width="95%">
    <tbody>
        <tr>
            <td>
            <h3><strong>
            <p align=center>104. Little shop of flowers </p>
            </h3>
            </strong>
            <p align=center>time limit per test: 0.50 sec. <br>memory limit per test: 4096 KB </p>
            <p align=justify></p>
            <p align=justify><font size=2></font><strong><font face=Tahoma size=2>
            <p>PROBLEM</p>
            </strong></font><font size=2>
            <p align=justify>You want to arrange the window of your flower shop in a most pleasant way. You have <em>F </em>bunches of flowers, each being of a different kind, and at least as many vases ordered in a row. The vases are glued onto the shelf and are numbered consecutively 1 through <em>V</em>, where <em>V</em> is the number of vases, from left to right so that the vase 1 is the leftmost, and the vase <em>V</em> is the rightmost vase. The bunches are moveable and are uniquely identified by integers between 1 and <em>F</em>. These id-numbers have a significance: They determine the required order of appearance of the flower bunches in the row of vases so that the bunch <em>i</em> must be in a vase to the left of the vase containing bunch <em>j</em> whenever <em>i</em> &lt; <em>j</em>. Suppose, for example, you have bunch of azaleas (id-number=1), a bunch of begonias (id-number=2) and a bunch of carnations (id-number=3). Now, all the bunches must be put into the vases keeping their id-numbers in order. The bunch of azaleas must be in a vase to the left of begonias, and the bunch of begonias must be in a vase to the left of carnations. If there are more vases than bunches of flowers then the excess will be left empty. A vase can hold only one bunch of flowers.</p>
            <p align=justify></p>
            <p align=justify>Each vase has a distinct characteristic (just like flowers do). Hence, putting a bunch of flowers in a vase results in a certain aesthetic value, expressed by an integer. The aesthetic values are presented in a table as shown below. Leaving a vase empty has an aesthetic value of 0.</p>
            <p align=justify></p>
            </font>
            <p align=left>
            <table borderColor=#000000 cellSpacing=2 cellPadding=7 width="90%" align=center border=1>
                <tbody>
                    <tr>
                        <td vAlign=top width="6%">&nbsp;</td>
                        <td vAlign=top width="35%">&nbsp;</td>
                        <td vAlign=top width="59%" colSpan=5><strong><font size=2>
                        <p align=center>V A S E S</strong></font></p>
                        </td>
                    </tr>
                    <tr>
                        <td vAlign=top width="6%">&nbsp;</td>
                        <td vAlign=top width="35%">&nbsp;</td>
                        <td vAlign=top width="13%"><strong><font size=2>
                        <p align=center>1</strong></font></p>
                        </td>
                        <td vAlign=top width="11%"><strong><font size=2>
                        <p align=center>2</strong></font></p>
                        </td>
                        <td vAlign=top width="11%"><strong><font size=2>
                        <p align=center>3</strong></font></p>
                        </td>
                        <td vAlign=top width="13%"><strong><font size=2>
                        <p align=center>4</strong></font></p>
                        </td>
                        <td vAlign=top width="11%"><strong><font size=2>
                        <p align=center>5</strong></font></p>
                        </td>
                    </tr>
                    <tr>
                        <td vAlign=center width="6%" height=26 rowSpan=3><strong><font size=2>
                        <p align=justify>Bunches</strong></font></p>
                        </td>
                        <td vAlign=center width="35%" height=26><strong><font size=2>
                        <p align=justify>1 (azaleas)</strong></font></p>
                        </td>
                        <td vAlign=center width="13%" height=26><font face=Courier size=2>
                        <p>7</font></p>
                        </td>
                        <td vAlign=center width="11%" height=26><font face=Courier size=2>
                        <p>23</font></p>
                        </td>
                        <td vAlign=center width="11%" height=26><font face=Courier size=2>
                        <p>-5</font></p>
                        </td>
                        <td vAlign=center width="13%" height=26><font face=Courier size=2>
                        <p>-24</font></p>
                        </td>
                        <td vAlign=center width="11%" height=26><font face=Courier size=2>
                        <p>16</font></p>
                        </td>
                    </tr>
                    <tr>
                        <td vAlign=center width="35%" height=26><strong><font size=2>
                        <p align=justify>2 (begonias)</strong></font></p>
                        </td>
                        <td vAlign=center width="13%" height=26><font face=Courier size=2>
                        <p>5</font></p>
                        </td>
                        <td vAlign=center width="11%" height=26><font face=Courier size=2>
                        <p>21</font></p>
                        </td>
                        <td vAlign=center width="11%" height=26><font face=Courier size=2>
                        <p>-4</font></p>
                        </td>
                        <td vAlign=center width="13%" height=26><font face=Courier size=2>
                        <p>10</font></p>
                        </td>
                        <td vAlign=center width="11%" height=26><font face=Courier size=2>
                        <p>23</font></p>
                        </td>
                    </tr>
                    <tr>
                        <td vAlign=center width="35%" height=26><strong><font size=2>
                        <p align=justify>3 (carnations)</strong></font></p>
                        </td>
                        <td vAlign=center width="13%" height=26><font face=Courier size=2>
                        <p align=center>-21</font></p>
                        </td>
                        <td vAlign=center width="11%" height=26><font face=Courier size=2>
                        <p>5</font></p>
                        </td>
                        <td vAlign=center width="11%" height=26><font face=Courier size=2>
                        <p>-4</font></p>
                        </td>
                        <td vAlign=center width="13%" height=26><font face=Courier size=2>
                        <p>-20</font></p>
                        </td>
                        <td vAlign=center width="11%" height=26><font face=Courier size=2>
                        <p>20</font></p>
                        </td>
                    </tr>
                </tbody>
            </table>
            </p>
            <font size=2>
            <p align=justify></p>
            <p align=justify>&nbsp;</p>
            <p align=justify>According to the table, azaleas, for example, would look great in vase 2, but they would look awful in vase 4.</p>
            <p align=justify></p>
            <p align=justify>To achieve the most pleasant effect you have to maximize the sum of aesthetic values for the arrangement while keeping the required ordering of the flowers. If more than one arrangement has the maximal sum value, any one of them will be acceptable. You have to produce exactly one arrangement.</p>
            <p align=justify></p>
            </font><strong><font face=Tahoma size=2>
            <p>ASSUMPTIONS</p>
            </strong></font><font size=2>
            <ul>
                <p align=justify>
                <li>1 &#8804; <em>F</em> &#8804; 100 where <em>F</em> is the number of the bunches of flowers. The bunches are numbered 1 through <em>F</em>.
                <p>&#160;</p>
                <em>
                <p align=justify></p>
                <li>F</em> &#8804; <em>V</em> &#8804; 100 where <em>V</em> is the number of vases.
                <p>&#160;</p>
                <p align=justify></p>
                <li>-50 <font face=Symbol>&#163;</font> <em>A<sub>ij</sub> </em><font face=Symbol>&#163;</font> 50 where <em>A<sub>ij </em></sub>is the aesthetic value obtained by putting the flower bunch <em>i</em> into the vase <em>j</em>.
                <p>&#160;</p>
                </li>
            </ul>
            </font>
            <p>&#160;</p>
            <p align=justify></p>
            <strong>
            <p align=justify>Input</p>
            </strong>
            <p align=justify><font size=2>
            <ul>
                <p align=justify>
                <li>The first line contains two numbers: <em>F</em>, <em>V</em>.
                <p>&#160;</p>
                <p align=justify></p>
                <li>The following <em>F</em> lines: Each of these lines contains <em>V</em> integers, so that <em>A<sub>ij</em></sub> is given as the <em>j</em>&#8217;th number on the (<em>i</em>+1)&#8217;st line of the input file.
                <p>&#160;</p>
                </li>
            </ul>
            </font>
            <p>&#160;</p>
            <p align=justify></p>
            <strong>
            <p align=justify>Output</p>
            </strong>
            <p align=justify><font size=2>
            <ul>
                <p align=justify>
                <li>The first line will contain the sum of aesthetic values for your arrangement.
                <p>&#160;</p>
                <p align=justify></p>
                <li>The second line must present the arrangement as a list of <em>F</em> numbers, so that the <em>k</em>&#8217;th number on this line identifies the vase in which the bunch <em>k</em> is put.
                <p>&#160;</p>
                </li>
            </ul>
            </font>
            <p>&#160;</p>
            <p align=justify></p>
            <p align=justify>Sample Input</p>
            <font face="Courier New">
            <pre>3 5
            7 23 -5 -24 16
            5 21 -4 10 23
            -21 5 -4 -20 20
            </pre>
            <p align=justify></p>
            </font>
            <p align=justify>Sample Output</p>
            <font face="Courier New">
            <pre>53
            2 4 5
            </pre>
            </font></td>
        </tr>
    </tbody>
</table>
Analysis<br><br>It is called a problem derived from IOI. As a typical DP problem, the only thing we need to think about is the dynamic function. This problem is harder since we need to record the tracy of dynamic programing.<br>Let's assume that dp[i][j] means the maximum sum of&nbsp; aesthetic values about first i flowers puts in first j vases. Then, since the only choice for the ith flower is whether put or not, the function is obvious: dp[i][j]=max{dp[i][j-1],dp[i-1][j-1]+a[i][j]}. Limitness is that i&lt;j should be held and record the action "put".<br><br>Code<br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">stdio.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">stdlib.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000">&nbsp;max(a,b)&nbsp;a&gt;b?a:b</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;dp[</span><span style="COLOR: #000000">101</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">101</span><span style="COLOR: #000000">];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;put[</span><span style="COLOR: #000000">101</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">101</span><span style="COLOR: #000000">];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;f,v;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;a[</span><span style="COLOR: #000000">101</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">101</span><span style="COLOR: #000000">];&nbsp;&nbsp;&nbsp;&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img id=Codehighlighter1_177_285_Open_Image onclick="this.style.display='none'; Codehighlighter1_177_285_Open_Text.style.display='none'; Codehighlighter1_177_285_Closed_Image.style.display='inline'; Codehighlighter1_177_285_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_177_285_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_177_285_Closed_Text.style.display='none'; Codehighlighter1_177_285_Open_Image.style.display='inline'; Codehighlighter1_177_285_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;putprint(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;j)</span><span id=Codehighlighter1_177_285_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_177_285_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">&nbsp;(put[i][j])&nbsp;j</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(i</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)&nbsp;putprint(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><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&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">f)&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,j);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,j);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img id=Codehighlighter1_298_702_Open_Image onclick="this.style.display='none'; Codehighlighter1_298_702_Open_Text.style.display='none'; Codehighlighter1_298_702_Closed_Image.style.display='inline'; Codehighlighter1_298_702_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_298_702_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_298_702_Closed_Text.style.display='none'; Codehighlighter1_298_702_Open_Image.style.display='inline'; Codehighlighter1_298_702_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()</span><span id=Codehighlighter1_298_702_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_298_702_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,j;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d&nbsp;%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">f,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">v);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">f;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(j</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">v;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&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">a[i][j]);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&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">&nbsp;dp);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">f;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_472_646_Open_Image onclick="this.style.display='none'; Codehighlighter1_472_646_Open_Text.style.display='none'; Codehighlighter1_472_646_Closed_Image.style.display='inline'; Codehighlighter1_472_646_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_472_646_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_472_646_Closed_Text.style.display='none'; Codehighlighter1_472_646_Open_Image.style.display='inline'; Codehighlighter1_472_646_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(j</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">v</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">f</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">i;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)</span><span id=Codehighlighter1_472_646_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_472_646_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp[i][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">32767</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">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">a[i][j];;put[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br><img id=Codehighlighter1_588_638_Open_Image onclick="this.style.display='none'; Codehighlighter1_588_638_Open_Text.style.display='none'; Codehighlighter1_588_638_Closed_Image.style.display='inline'; Codehighlighter1_588_638_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_588_638_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_588_638_Closed_Text.style.display='none'; Codehighlighter1_588_638_Open_Image.style.display='inline'; Codehighlighter1_588_638_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&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][j</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">(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">a[i][j]))</span><span id=Codehighlighter1_588_638_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_588_638_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">dp[i][j</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;put[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&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">,dp[f][v]);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;putprint(f,v);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&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><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span></div>
<img src ="http://www.cppblog.com/master0503/aggbug/65840.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/master0503/" target="_blank">幻浪天空领主</a> 2008-11-03 14:35 <a href="http://www.cppblog.com/master0503/articles/65840.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>