﻿<?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++博客-&amp;豪-文章分类-ACM题目</title><link>http://www.cppblog.com/qywyh/category/1629.html</link><description>豪-&gt;blog</description><language>zh-cn</language><lastBuildDate>Mon, 19 May 2008 14:36:20 GMT</lastBuildDate><pubDate>Mon, 19 May 2008 14:36:20 GMT</pubDate><ttl>60</ttl><item><title>pku3311</title><link>http://www.cppblog.com/qywyh/articles/29328.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Fri, 03 Aug 2007 14:57:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/29328.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/29328.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/29328.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/29328.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/29328.html</trackback:ping><description><![CDATA[<p align=center><font color=blue size=5></p>
<p align=center>Hie with the Pie</font> <br>Time Limit:2000MS&nbsp; Memory Limit:65536K<br>Total Submit:501 Accepted:183 </p>
<p><font color=blue size=5>Description</font><br><font face="Times New Roman" size=3>
<p>The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortunately, due to cutbacks, they can afford to hire only one driver to do the deliveries. He will wait for 1 or more (up to 10) orders to be processed before he starts any deliveries. Needless to say, he would like to take the shortest route in delivering these goodies and returning to the pizzeria, even if it means passing the same location(s) or the pizzeria more than once on the way. He has commissioned you to write a program to help him.</p>
</font>
<p>&#160;</p>
<p><font color=blue size=5>Input</font><br><font face="Times New Roman" size=3>
<p>Input will consist of multiple test cases. The first line will contain a single integer <em>n</em> indicating the number of orders to deliver, where 1 &#8804; <em>n</em> &#8804; 10. After this will be <em>n</em> + 1 lines each containing <em>n</em> + 1 integers indicating the times to travel between the pizzeria (numbered 0) and the <em>n</em> locations (numbers 1 to <em>n</em>). The <em>j</em>th value on the <em>i</em>th line indicates the time to go directly from location <em>i</em> to location <em>j</em> without visiting any other locations along the way. Note that there may be quicker ways to go from <em>i</em> to <em>j</em> via other locations, due to different speed limits, traffic lights, etc. Also, the time values may not be symmetric, i.e., the time to go directly from location <em>i</em> to <em>j</em> may not be the same as the time to go directly from location <em>j</em> to <em>i</em>. An input value of <em>n</em> = 0 will terminate input.</p>
</font>
<p>&#160;</p>
<p><font color=blue size=5>Output</font><br><font face="Times New Roman" size=3>
<p>For each test case, you should output a single number indicating the minimum time to deliver all of the pizzas and return to the pizzeria.</p>
</font>
<p>&#160;</p>
<p><font color=blue size=5>Sample Input</font><br><font face="Times New Roman" size=3>
<pre>3
0 1 10 10
1 0 1 2
10 1 0 10
10 2 10 0
0</pre>
</font>
<p>&#160;</p>
<p><font color=blue size=5>Sample Output</font><br><font face="Times New Roman" size=3>
<pre>8</pre>
</font>
<p>&#160;</p>
<p><font color=blue size=5>Source</font><br><font face="Times New Roman" color=#0000ff size=3><a href="http://acm.pku.edu.cn/JudgeOnline/searchproblem?field=source&amp;key=East Central North America 2006"><u>East Central North America 2006</u></a><br></p>
<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" twffan="done"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"><span style="COLOR: #000000" twffan="done">#include&nbsp;</span><span style="COLOR: #000000" twffan="done">&lt;</span><span style="COLOR: #000000" twffan="done">cstdio</span><span style="COLOR: #000000" twffan="done">&gt;</span><span style="COLOR: #000000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">#include&nbsp;</span><span style="COLOR: #000000" twffan="done">&lt;</span><span style="COLOR: #000000" twffan="done">memory</span><span style="COLOR: #000000" twffan="done">&gt;</span><span style="COLOR: #000000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">const</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;INF&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;0x7fffffff;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;n,&nbsp;d[</span><span style="COLOR: #000000" twffan="done">12</span><span style="COLOR: #000000" twffan="done">][</span><span style="COLOR: #000000" twffan="done">2100</span><span style="COLOR: #000000" twffan="done">];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;g[</span><span style="COLOR: #000000" twffan="done">12</span><span style="COLOR: #000000" twffan="done">][</span><span style="COLOR: #000000" twffan="done">12</span><span style="COLOR: #000000" twffan="done">];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">void&nbsp;floyd()&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;i,&nbsp;j,&nbsp;k;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">for</span><span style="COLOR: #000000" twffan="done">&nbsp;(k</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">;&nbsp;k</span><span style="COLOR: #000000" twffan="done">&lt;=</span><span style="COLOR: #000000" twffan="done">n;&nbsp;k</span><span style="COLOR: #000000" twffan="done">++</span><span style="COLOR: #000000" twffan="done">)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">for</span><span style="COLOR: #000000" twffan="done">&nbsp;(i</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">;&nbsp;i</span><span style="COLOR: #000000" twffan="done">&lt;=</span><span style="COLOR: #000000" twffan="done">n;&nbsp;i</span><span style="COLOR: #000000" twffan="done">++</span><span style="COLOR: #000000" twffan="done">)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">for</span><span style="COLOR: #000000" twffan="done">&nbsp;(j</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">;&nbsp;j</span><span style="COLOR: #000000" twffan="done">&lt;=</span><span style="COLOR: #000000" twffan="done">n;&nbsp;j</span><span style="COLOR: #000000" twffan="done">++</span><span style="COLOR: #000000" twffan="done">)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">if</span><span style="COLOR: #000000" twffan="done">&nbsp;(g[i][k]&nbsp;!</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">&amp;&amp;</span><span style="COLOR: #000000" twffan="done">&nbsp;g[k][j]&nbsp;!</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">&amp;&amp;</span><span style="COLOR: #000000" twffan="done">&nbsp;(g[i][j]&nbsp;</span><span style="COLOR: #000000" twffan="done">==</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">&nbsp;||&nbsp;g[i][k]</span><span style="COLOR: #000000" twffan="done">+</span><span style="COLOR: #000000" twffan="done">g[k][j]&nbsp;</span><span style="COLOR: #000000" twffan="done">&lt;</span><span style="COLOR: #000000" twffan="done">&nbsp;g[i][j]))&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g[i][j]&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;g[i][k]&nbsp;</span><span style="COLOR: #000000" twffan="done">+</span><span style="COLOR: #000000" twffan="done">&nbsp;g[k][j];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&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/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">void&nbsp;solve()&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;i,&nbsp;j,&nbsp;k,&nbsp;bit,&nbsp;t,&nbsp;tmp,&nbsp;one[</span><span style="COLOR: #000000" twffan="done">15</span><span style="COLOR: #000000" twffan="done">],&nbsp;tmpb,&nbsp;ans&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;INF;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;memset(d,&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">,&nbsp;sizeof(d));<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;memset(g,&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">,&nbsp;sizeof(g));<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">for</span><span style="COLOR: #000000" twffan="done">&nbsp;(i</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">;&nbsp;i</span><span style="COLOR: #000000" twffan="done">&lt;=</span><span style="COLOR: #000000" twffan="done">n;&nbsp;i</span><span style="COLOR: #000000" twffan="done">++</span><span style="COLOR: #000000" twffan="done">)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">for</span><span style="COLOR: #000000" twffan="done">&nbsp;(j</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">;&nbsp;j</span><span style="COLOR: #000000" twffan="done">&lt;=</span><span style="COLOR: #000000" twffan="done">n;&nbsp;j</span><span style="COLOR: #000000" twffan="done">++</span><span style="COLOR: #000000" twffan="done">)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">%d</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">,&nbsp;</span><span style="COLOR: #000000" twffan="done">&amp;</span><span style="COLOR: #000000" twffan="done">g[i][j]);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;floyd();<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;d[</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">][</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">]&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">for</span><span style="COLOR: #000000" twffan="done">&nbsp;(i</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">;&nbsp;i</span><span style="COLOR: #000000" twffan="done">&lt;=</span><span style="COLOR: #000000" twffan="done">n;&nbsp;i</span><span style="COLOR: #000000" twffan="done">++</span><span style="COLOR: #000000" twffan="done">)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">for</span><span style="COLOR: #000000" twffan="done">&nbsp;(j</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">;&nbsp;j</span><span style="COLOR: #000000" twffan="done">&lt;</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">&lt;&lt;</span><span style="COLOR: #000000" twffan="done">(n</span><span style="COLOR: #000000" twffan="done">+</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">);&nbsp;j</span><span style="COLOR: #000000" twffan="done">++</span><span style="COLOR: #000000" twffan="done">)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bit&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;j;&nbsp;tmp&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">for</span><span style="COLOR: #000000" twffan="done">&nbsp;(k</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">;&nbsp;k</span><span style="COLOR: #000000" twffan="done">&lt;=</span><span style="COLOR: #000000" twffan="done">n;&nbsp;k</span><span style="COLOR: #000000" twffan="done">++</span><span style="COLOR: #000000" twffan="done">)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">if</span><span style="COLOR: #000000" twffan="done">&nbsp;(bit</span><span style="COLOR: #000000" twffan="done">&amp;</span><span style="COLOR: #000000" twffan="done">(</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">&lt;&lt;</span><span style="COLOR: #000000" twffan="done">k)&nbsp;</span><span style="COLOR: #000000" twffan="done">&amp;&amp;</span><span style="COLOR: #000000" twffan="done">&nbsp;bit</span><span style="COLOR: #000000" twffan="done">&amp;</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;one[tmp</span><span style="COLOR: #000000" twffan="done">++</span><span style="COLOR: #000000" twffan="done">]&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;k;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&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/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">if</span><span style="COLOR: #000000" twffan="done">&nbsp;(tmp&nbsp;!</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;i)&nbsp;continue;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">for</span><span style="COLOR: #000000" twffan="done">&nbsp;(k</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">;&nbsp;k</span><span style="COLOR: #000000" twffan="done">&lt;</span><span style="COLOR: #000000" twffan="done">tmp;&nbsp;k</span><span style="COLOR: #000000" twffan="done">++</span><span style="COLOR: #000000" twffan="done">)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmpb&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;bit</span><span style="COLOR: #000000" twffan="done">^</span><span style="COLOR: #000000" twffan="done">(</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">&lt;&lt;</span><span style="COLOR: #000000" twffan="done">one[k]);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">if</span><span style="COLOR: #000000" twffan="done">&nbsp;(d[</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">][tmpb]&nbsp;!</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">&amp;&amp;</span><span style="COLOR: #000000" twffan="done">&nbsp;g[</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">][one[k]]&nbsp;!</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&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" twffan="done">if</span><span style="COLOR: #000000" twffan="done">&nbsp;(d[one[k]][bit]&nbsp;</span><span style="COLOR: #000000" twffan="done">==</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">&nbsp;||&nbsp;d[one[k]][bit]&nbsp;</span><span style="COLOR: #000000" twffan="done">&gt;</span><span style="COLOR: #000000" twffan="done">&nbsp;g[</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">][one[k]]&nbsp;</span><span style="COLOR: #000000" twffan="done">+</span><span style="COLOR: #000000" twffan="done">&nbsp;d[</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">][tmpb])&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d[one[k]][bit]&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;g[</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">][one[k]]&nbsp;</span><span style="COLOR: #000000" twffan="done">+</span><span style="COLOR: #000000" twffan="done">&nbsp;d[</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">][tmpb];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&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/None.gif" align=top twffan="done">&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/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">for</span><span style="COLOR: #000000" twffan="done">&nbsp;(t</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">;&nbsp;t</span><span style="COLOR: #000000" twffan="done">&lt;</span><span style="COLOR: #000000" twffan="done">tmp;&nbsp;t</span><span style="COLOR: #000000" twffan="done">++</span><span style="COLOR: #000000" twffan="done">)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&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" twffan="done">if</span><span style="COLOR: #000000" twffan="done">&nbsp;(t&nbsp;</span><span style="COLOR: #000000" twffan="done">==</span><span style="COLOR: #000000" twffan="done">&nbsp;k)&nbsp;continue;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&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" twffan="done">if</span><span style="COLOR: #000000" twffan="done">&nbsp;(d[one[t]][tmpb]&nbsp;!</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">&amp;&amp;</span><span style="COLOR: #000000" twffan="done">&nbsp;g[one[t]][one[k]]&nbsp;!</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&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" twffan="done">if</span><span style="COLOR: #000000" twffan="done">&nbsp;(d[one[k]][bit]&nbsp;</span><span style="COLOR: #000000" twffan="done">==</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">&nbsp;||&nbsp;d[one[k]][bit]&nbsp;</span><span style="COLOR: #000000" twffan="done">&gt;</span><span style="COLOR: #000000" twffan="done">&nbsp;g[one[t]][one[k]]&nbsp;</span><span style="COLOR: #000000" twffan="done">+</span><span style="COLOR: #000000" twffan="done">&nbsp;d[one[t]][tmpb])&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&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;&nbsp;d[one[k]][bit]&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;g[one[t]][one[k]]&nbsp;</span><span style="COLOR: #000000" twffan="done">+</span><span style="COLOR: #000000" twffan="done">&nbsp;d[one[t]][tmpb];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&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/None.gif" align=top twffan="done">&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/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">for</span><span style="COLOR: #000000" twffan="done">&nbsp;(i</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">;&nbsp;i</span><span style="COLOR: #000000" twffan="done">&lt;=</span><span style="COLOR: #000000" twffan="done">n;&nbsp;i</span><span style="COLOR: #000000" twffan="done">++</span><span style="COLOR: #000000" twffan="done">)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">if</span><span style="COLOR: #000000" twffan="done">&nbsp;(d[i][(</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">&lt;&lt;</span><span style="COLOR: #000000" twffan="done">n</span><span style="COLOR: #000000" twffan="done">+</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">)</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">]&nbsp;!</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">&amp;&amp;</span><span style="COLOR: #000000" twffan="done">&nbsp;g[i][</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">]&nbsp;!</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">&amp;&amp;</span><span style="COLOR: #000000" twffan="done">&nbsp;ans&nbsp;</span><span style="COLOR: #000000" twffan="done">&gt;</span><span style="COLOR: #000000" twffan="done">&nbsp;d[i][(</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">&lt;&lt;</span><span style="COLOR: #000000" twffan="done">n</span><span style="COLOR: #000000" twffan="done">+</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">)</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">]</span><span style="COLOR: #000000" twffan="done">+</span><span style="COLOR: #000000" twffan="done">g[i][</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">])&nbsp;ans&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;d[i][(</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">&lt;&lt;</span><span style="COLOR: #000000" twffan="done">n</span><span style="COLOR: #000000" twffan="done">+</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">)</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">]</span><span style="COLOR: #000000" twffan="done">+</span><span style="COLOR: #000000" twffan="done">g[i][</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">%d\n</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">,&nbsp;ans);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;main()&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">while</span><span style="COLOR: #000000" twffan="done">&nbsp;(scanf(</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">%d</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">,&nbsp;</span><span style="COLOR: #000000" twffan="done">&amp;</span><span style="COLOR: #000000" twffan="done">n)&nbsp;!</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;EOF)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">if</span><span style="COLOR: #000000" twffan="done">&nbsp;(n&nbsp;</span><span style="COLOR: #000000" twffan="done">==</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">)&nbsp;break;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;solve();<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">}</span></div>
<p><br></font></p>
<img src ="http://www.cppblog.com/qywyh/aggbug/29328.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-08-03 22:57 <a href="http://www.cppblog.com/qywyh/articles/29328.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku3268 dij+heap</title><link>http://www.cppblog.com/qywyh/articles/28653.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Mon, 23 Jul 2007 12:51:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/28653.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/28653.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/28653.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/28653.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/28653.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 写了个比较通用的堆，可直接用作优先队列Silver Cow Party Time Limit:2000MS&nbsp; Memory Limit:65536KTotal Submit:1112 Accepted:326 DescriptionOne cow from each of N farms (1 &#8804; N &#8804; 1000) conveniently numb...&nbsp;&nbsp;<a href='http://www.cppblog.com/qywyh/articles/28653.html'>阅读全文</a><img src ="http://www.cppblog.com/qywyh/aggbug/28653.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-07-23 20:51 <a href="http://www.cppblog.com/qywyh/articles/28653.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ural 1018(简单的树状dp)</title><link>http://www.cppblog.com/qywyh/articles/22412.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Fri, 20 Apr 2007 12:05:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/22412.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/22412.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/22412.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/22412.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/22412.html</trackback:ping><description><![CDATA[<div align=center twffan="done">
<div class=title twffan="done">1018. A Binary Apple Tree</div>
Time Limit: 1.0 second<br>Memory Limit: 16 MB<br></div>
<p>Let's imagine how apple tree looks in binary computer world. You're right, it looks just like a binary tree, i.e. any biparous branch splits up to exactly two new branches. We will enumerate by natural numbers the root of binary apple tree, points of branching and the ends of twigs. This way we may distinguish different branches by their ending points. We will assume that root of tree always is numbered by 1 and all numbers used for enumerating are numbered in range from 1 to <em>N</em>, where <em>N</em> is the total number of all enumerated points. For instance in the picture below <em>N</em> is equal to 5. Here is an example of an enumerated tree with four branches:<br>
<pre>   2   5
\ /
3   4
\ /
1
</pre>
As you may know it's not convenient to pick an apples from a tree when there are too much of branches. That's why some of them should be removed from a tree. But you are interested in removing branches in the way of minimal loss of apples. So your are given amounts of apples on a branches and amount of branches that should be preserved. Your task is to determine how many apples can remain on a tree after removing of excessive branches.
<p>&#160;</p>
<h3 class=subtitle>Input</h3>
<p>First line of input contains two numbers: <em>N</em> and <em>Q</em> (1 &#8804; <em>Q</em> &#8804; <em>N</em>, 1 &lt; <em>N</em> &#8804; 100). <em>N</em> denotes the number of enumerated points in a tree. <em>Q</em> denotes amount of branches that should be preserved. Next <em>N</em>-1 lines contains descriptions of branches. Each description consists of a three integer numbers divided by spaces. The first two of them define branch by it's ending points. The third number defines the number of apples on this branch. You may assume that no branch contains more than 30000 apples.</p>
<h3 class=subtitle>Output</h3>
<p>Output file should contain the only number — amount of apples that can be preserved. And don't forget to preserve tree's root ;-)</p>
<h3 class=subtitle>Sample</h3>
<table class=sample>
    <tbody>
        <tr>
            <th>
            <div twffan="done">input</div>
            </th>
            <th>
            <div twffan="done">output</div>
            </th>
        </tr>
        <tr>
            <td>
            <pre>5 2
            1 3 1
            1 4 10
            2 3 20
            3 5 20
            </pre>
            </td>
            <td>
            <pre>21
            </pre>
            </td>
        </tr>
    </tbody>
</table>
<br><strong>Problem Source: </strong>Ural State University Internal Contest '99 #2 <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" twffan="done"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"><span style="COLOR: #000000" twffan="done">#include&nbsp;</span><span style="COLOR: #000000" twffan="done">&lt;</span><span style="COLOR: #000000" twffan="done">iostream</span><span style="COLOR: #000000" twffan="done">&gt;</span><span style="COLOR: #000000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">using</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #0000ff" twffan="done">namespace</span><span style="COLOR: #000000" twffan="done">&nbsp;std;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">const</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;MAXN&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">110</span><span style="COLOR: #000000" twffan="done">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">const</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;MAXQ&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">110</span><span style="COLOR: #000000" twffan="done">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;n,&nbsp;q;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;d[MAXN][MAXQ];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;g[MAXN][MAXN],&nbsp;deg[MAXN],&nbsp;nw[MAXN],&nbsp;son[MAXN][</span><span style="COLOR: #000000" twffan="done">2</span><span style="COLOR: #000000" twffan="done">];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;root;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;f[MAXN],&nbsp;isleaf[MAXN];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"><br><img id=Codehighlighter1_238_263_Open_Image onclick="this.style.display='none'; Codehighlighter1_238_263_Open_Text.style.display='none'; Codehighlighter1_238_263_Closed_Image.style.display='inline'; Codehighlighter1_238_263_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_238_263_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_238_263_Closed_Text.style.display='none'; Codehighlighter1_238_263_Open_Image.style.display='inline'; Codehighlighter1_238_263_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top twffan="done">inline&nbsp;</span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;maxt(</span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;a,&nbsp;</span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;b)&nbsp;</span><span id=Codehighlighter1_238_263_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" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_238_263_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">return</span><span style="COLOR: #000000" twffan="done">&nbsp;a&nbsp;</span><span style="COLOR: #000000" twffan="done">&gt;</span><span style="COLOR: #000000" twffan="done">&nbsp;b&nbsp;</span><span style="COLOR: #000000" twffan="done">?</span><span style="COLOR: #000000" twffan="done">&nbsp;a&nbsp;:&nbsp;b;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top twffan="done">}</span></span><span style="COLOR: #000000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"><br><img id=Codehighlighter1_282_450_Open_Image onclick="this.style.display='none'; Codehighlighter1_282_450_Open_Text.style.display='none'; Codehighlighter1_282_450_Closed_Image.style.display='inline'; Codehighlighter1_282_450_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_282_450_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_282_450_Closed_Text.style.display='none'; Codehighlighter1_282_450_Open_Image.style.display='inline'; Codehighlighter1_282_450_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">void</span><span style="COLOR: #000000" twffan="done">&nbsp;DFS(</span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;v)&nbsp;</span><span id=Codehighlighter1_282_450_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" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_282_450_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;i,&nbsp;t&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">;<br><img id=Codehighlighter1_321_424_Open_Image onclick="this.style.display='none'; Codehighlighter1_321_424_Open_Text.style.display='none'; Codehighlighter1_321_424_Closed_Image.style.display='inline'; Codehighlighter1_321_424_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_321_424_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_321_424_Closed_Text.style.display='none'; Codehighlighter1_321_424_Open_Image.style.display='inline'; Codehighlighter1_321_424_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">for</span><span style="COLOR: #000000" twffan="done">&nbsp;(i</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">;&nbsp;i</span><span style="COLOR: #000000" twffan="done">&lt;=</span><span style="COLOR: #000000" twffan="done">n;&nbsp;i</span><span style="COLOR: #000000" twffan="done">++</span><span style="COLOR: #000000" twffan="done">)&nbsp;</span><span id=Codehighlighter1_321_424_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" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_321_424_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{<br><img id=Codehighlighter1_353_421_Open_Image onclick="this.style.display='none'; Codehighlighter1_353_421_Open_Text.style.display='none'; Codehighlighter1_353_421_Closed_Image.style.display='inline'; Codehighlighter1_353_421_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_353_421_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_353_421_Closed_Text.style.display='none'; Codehighlighter1_353_421_Open_Image.style.display='inline'; Codehighlighter1_353_421_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">if</span><span style="COLOR: #000000" twffan="done">&nbsp;(g[v][i]&nbsp;</span><span style="COLOR: #000000" twffan="done">!=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">&amp;&amp;</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">!</span><span style="COLOR: #000000" twffan="done">f[i])&nbsp;</span><span id=Codehighlighter1_353_421_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" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_353_421_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;son[v][t</span><span style="COLOR: #000000" twffan="done">++</span><span style="COLOR: #000000" twffan="done">]&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;i;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f[i]&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nw[i]&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;g[v][i];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DFS(i);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">if</span><span style="COLOR: #000000" twffan="done">&nbsp;(</span><span style="COLOR: #000000" twffan="done">!</span><span style="COLOR: #000000" twffan="done">t)&nbsp;isleaf[v]&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top twffan="done">}</span></span><span style="COLOR: #000000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"><br><img id=Codehighlighter1_467_592_Open_Image onclick="this.style.display='none'; Codehighlighter1_467_592_Open_Text.style.display='none'; Codehighlighter1_467_592_Closed_Image.style.display='inline'; Codehighlighter1_467_592_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_467_592_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_467_592_Closed_Text.style.display='none'; Codehighlighter1_467_592_Open_Image.style.display='inline'; Codehighlighter1_467_592_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">void</span><span style="COLOR: #000000" twffan="done">&nbsp;buildT()&nbsp;</span><span id=Codehighlighter1_467_592_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" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_467_592_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;i;<br><img id=Codehighlighter1_499_550_Open_Image onclick="this.style.display='none'; Codehighlighter1_499_550_Open_Text.style.display='none'; Codehighlighter1_499_550_Closed_Image.style.display='inline'; Codehighlighter1_499_550_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_499_550_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_499_550_Closed_Text.style.display='none'; Codehighlighter1_499_550_Open_Image.style.display='inline'; Codehighlighter1_499_550_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">for</span><span style="COLOR: #000000" twffan="done">&nbsp;(i</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">;&nbsp;i</span><span style="COLOR: #000000" twffan="done">&lt;=</span><span style="COLOR: #000000" twffan="done">n;&nbsp;i</span><span style="COLOR: #000000" twffan="done">++</span><span style="COLOR: #000000" twffan="done">)&nbsp;</span><span id=Codehighlighter1_499_550_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" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_499_550_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{<br><img id=Codehighlighter1_520_547_Open_Image onclick="this.style.display='none'; Codehighlighter1_520_547_Open_Text.style.display='none'; Codehighlighter1_520_547_Closed_Image.style.display='inline'; Codehighlighter1_520_547_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_520_547_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_520_547_Closed_Text.style.display='none'; Codehighlighter1_520_547_Open_Image.style.display='inline'; Codehighlighter1_520_547_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">if</span><span style="COLOR: #000000" twffan="done">&nbsp;(deg[i]&nbsp;</span><span style="COLOR: #000000" twffan="done">==</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">2</span><span style="COLOR: #000000" twffan="done">)&nbsp;</span><span id=Codehighlighter1_520_547_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" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_520_547_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;root&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;i;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">break</span><span style="COLOR: #000000" twffan="done">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;f[root]&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">;&nbsp;nw[root]&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;DFS(root);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top twffan="done">}</span></span><span style="COLOR: #000000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"><br><img id=Codehighlighter1_618_867_Open_Image onclick="this.style.display='none'; Codehighlighter1_618_867_Open_Text.style.display='none'; Codehighlighter1_618_867_Closed_Image.style.display='inline'; Codehighlighter1_618_867_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_618_867_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_618_867_Closed_Text.style.display='none'; Codehighlighter1_618_867_Open_Image.style.display='inline'; Codehighlighter1_618_867_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;DP(</span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;ti,&nbsp;</span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;tl)&nbsp;</span><span id=Codehighlighter1_618_867_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" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_618_867_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">if</span><span style="COLOR: #000000" twffan="done">&nbsp;(tl&nbsp;</span><span style="COLOR: #000000" twffan="done">&lt;=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">)&nbsp;</span><span style="COLOR: #0000ff" twffan="done">return</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">if</span><span style="COLOR: #000000" twffan="done">&nbsp;(d[ti][tl]&nbsp;</span><span style="COLOR: #000000" twffan="done">!=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">)&nbsp;</span><span style="COLOR: #0000ff" twffan="done">return</span><span style="COLOR: #000000" twffan="done">&nbsp;d[ti][tl];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">if</span><span style="COLOR: #000000" twffan="done">&nbsp;(isleaf[ti])&nbsp;</span><span style="COLOR: #0000ff" twffan="done">return</span><span style="COLOR: #000000" twffan="done">&nbsp;nw[ti];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;k,&nbsp;tmp&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">;<br><img id=Codehighlighter1_755_819_Open_Image onclick="this.style.display='none'; Codehighlighter1_755_819_Open_Text.style.display='none'; Codehighlighter1_755_819_Closed_Image.style.display='inline'; Codehighlighter1_755_819_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_755_819_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_755_819_Closed_Text.style.display='none'; Codehighlighter1_755_819_Open_Image.style.display='inline'; Codehighlighter1_755_819_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">for</span><span style="COLOR: #000000" twffan="done">&nbsp;(k</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">;&nbsp;k</span><span style="COLOR: #000000" twffan="done">&lt;</span><span style="COLOR: #000000" twffan="done">tl;&nbsp;k</span><span style="COLOR: #000000" twffan="done">++</span><span style="COLOR: #000000" twffan="done">)&nbsp;</span><span id=Codehighlighter1_755_819_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" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_755_819_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;maxt(tmp,&nbsp;DP(son[ti][</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">],&nbsp;k)</span><span style="COLOR: #000000" twffan="done">+</span><span style="COLOR: #000000" twffan="done">DP(son[ti][</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">],&nbsp;tl</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">k));<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;d[ti][tl]&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;tmp&nbsp;</span><span style="COLOR: #000000" twffan="done">+</span><span style="COLOR: #000000" twffan="done">&nbsp;nw[ti];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">return</span><span style="COLOR: #000000" twffan="done">&nbsp;d[ti][tl];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top twffan="done">}</span></span><span style="COLOR: #000000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"><br><img id=Codehighlighter1_881_1147_Open_Image onclick="this.style.display='none'; Codehighlighter1_881_1147_Open_Text.style.display='none'; Codehighlighter1_881_1147_Closed_Image.style.display='inline'; Codehighlighter1_881_1147_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_881_1147_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_881_1147_Closed_Text.style.display='none'; Codehighlighter1_881_1147_Open_Image.style.display='inline'; Codehighlighter1_881_1147_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;main()&nbsp;</span><span id=Codehighlighter1_881_1147_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" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_881_1147_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;i,&nbsp;j,&nbsp;k,&nbsp;x,&nbsp;y,&nbsp;w;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">%d%d</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">,&nbsp;</span><span style="COLOR: #000000" twffan="done">&amp;</span><span style="COLOR: #000000" twffan="done">n,&nbsp;</span><span style="COLOR: #000000" twffan="done">&amp;</span><span style="COLOR: #000000" twffan="done">q);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;memset(g,&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">,&nbsp;</span><span style="COLOR: #0000ff" twffan="done">sizeof</span><span style="COLOR: #000000" twffan="done">(g));<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;memset(d,&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">,&nbsp;</span><span style="COLOR: #0000ff" twffan="done">sizeof</span><span style="COLOR: #000000" twffan="done">(d));<br><img id=Codehighlighter1_1007_1089_Open_Image onclick="this.style.display='none'; Codehighlighter1_1007_1089_Open_Text.style.display='none'; Codehighlighter1_1007_1089_Closed_Image.style.display='inline'; Codehighlighter1_1007_1089_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_1007_1089_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1007_1089_Closed_Text.style.display='none'; Codehighlighter1_1007_1089_Open_Image.style.display='inline'; Codehighlighter1_1007_1089_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">for</span><span style="COLOR: #000000" twffan="done">&nbsp;(i</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">;&nbsp;i</span><span style="COLOR: #000000" twffan="done">&lt;</span><span style="COLOR: #000000" twffan="done">n</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">;&nbsp;i</span><span style="COLOR: #000000" twffan="done">++</span><span style="COLOR: #000000" twffan="done">)&nbsp;</span><span id=Codehighlighter1_1007_1089_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" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_1007_1089_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">%d%d%d</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">,&nbsp;</span><span style="COLOR: #000000" twffan="done">&amp;</span><span style="COLOR: #000000" twffan="done">x,&nbsp;</span><span style="COLOR: #000000" twffan="done">&amp;</span><span style="COLOR: #000000" twffan="done">y,&nbsp;</span><span style="COLOR: #000000" twffan="done">&amp;</span><span style="COLOR: #000000" twffan="done">w);&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g[x][y]&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;g[y][x]&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;w;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;deg[x]</span><span style="COLOR: #000000" twffan="done">++</span><span style="COLOR: #000000" twffan="done">,&nbsp;deg[y]</span><span style="COLOR: #000000" twffan="done">++</span><span style="COLOR: #000000" twffan="done">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;buildT();<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">%d\n</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">,&nbsp;DP(root,&nbsp;q</span><span style="COLOR: #000000" twffan="done">+</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">));<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">return</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top twffan="done">}</span></span></div>
<br>
<img src ="http://www.cppblog.com/qywyh/aggbug/22412.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-04-20 20:05 <a href="http://www.cppblog.com/qywyh/articles/22412.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>挺难的状态DP pku 1038</title><link>http://www.cppblog.com/qywyh/articles/22199.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Wed, 18 Apr 2007 03:42:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/22199.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/22199.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/22199.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/22199.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/22199.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Bugs Integrated, Inc. Time Limit:15000MS&nbsp; Memory Limit:30000KTotal Submit:1180 Accepted:309 Case Time Limit:5000MS DescriptionBugs Integrated, Inc. is a major manufacturer of advanced memory ch...&nbsp;&nbsp;<a href='http://www.cppblog.com/qywyh/articles/22199.html'>阅读全文</a><img src ="http://www.cppblog.com/qywyh/aggbug/22199.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-04-18 11:42 <a href="http://www.cppblog.com/qywyh/articles/22199.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku2904 3维dp</title><link>http://www.cppblog.com/qywyh/articles/20583.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Sun, 25 Mar 2007 16:41:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/20583.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/20583.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/20583.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/20583.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/20583.html</trackback:ping><description><![CDATA[开始时候粗心，状态转移时候k写成k-1了，查了n久.<br /><br /><p align="center"><font color="blue" size="5">The Mailboxes Manufacturers Problem</font><br />Time Limit:1000MS  Memory Limit:65536K<br />Total Submit:299 Accepted:227 </p><p><font color="blue" size="5">Description</font><br /><font face="Times New Roman" size="3"><span lang="en-us" twffan="done"><p>In the good old days when Swedish children were still allowed to blowup their fingers with fire-crackers, gangs of excited kids would plague certain smaller cities during Easter time, with only one thing in mind: To blow things up. Small boxes were easy to blow up, and thus mailboxes became a popular target. Now, a small mailbox manufacturer is interested in how many fire-crackers his new mailbox prototype can withstand without exploding and has hired you to help him. He will provide you with <i>k</i> (1 ≤ <i>k</i> ≤ 10) identical mailbox prototypes each fitting up to <i>m</i> (1 ≤ <i>m</i> ≤ 100) crackers. However, he is not sure of how many firecrackers he needs to provide you with in order for you to be able to solve his problem, so he asks you. You think for a while and then say, “Well,if I blow up a mailbox I can’t use it again, so if you would provide me with only <i>k</i> = 1 mailboxes, I would have to start testing with 1 cracker, then 2 crackers, and so on until it finally exploded. In the worst case, that is if it does not blow up even when filled with m crackers, I would need 1 + 2 + 3 + … + <i>m</i> = <i>m</i> × (<i>m</i> + 1) ⁄ 2 crackers. If <i>m</i> = 100 that would mean more than 5000 fire-crackers!” “That’s too many,” he replies. “What if I give you more than <i>k</i> = 1 mailboxes? Can you find a strategy that requires less crackers?”</p><p>Can you? And what is the minimum number of crackers that you should ask him to provide you with?</p><p>You may assume the following:</p><ol><li>If a mailbox can withstand <i>x</i> fire-crackers, it can also withstand <i>x</i> − 1 fire-crackers. 
</li><li>Upon an explosion, a mailbox is either totally destroyed (blown up) or unharmed, which means that it can be reused in another test explosion.</li></ol><p>Note: If the mailbox can withstand a full load of <i>m</i> fire-crackers, then the manufacturer will of course be satisfied with that answer. But otherwise he is looking for the maximum number of crackers that his mailboxes can withstand.</p></span></font></p><p></p><p><font color="blue" size="5">Input</font><br /><font face="Times New Roman" size="3"><span lang="en-us" twffan="done"><p>The input starts with a single integer <i>N</i> (1 ≤ <i>N</i> ≤ 10) indicating the number of test cases to follow. Each test case is described by a line containing two integers: <i>k</i> and <i>m</i>, separated by a single space.</p></span></font></p><p></p><p><font color="blue" size="5">Output</font><br /><font face="Times New Roman" size="3"><p>For each test case print one line with a single integer indicating the minimum number of fire-crackers that is needed, in the worst case, in order to figure out how many crackers the mailbox prototype can withstand.</p></font></p><p></p><p><font color="blue" size="5">Sample Input</font><br /><font face="Times New Roman" size="3"><pre>4
1 10
1 100
3 73
5 100</pre></font></p><p></p><p><font color="blue" size="5">Sample Output</font><br /><font face="Times New Roman" size="3"><pre>55
5050
382
495</pre></font></p><p></p><p><font color="blue" size="5">Source</font><br /><font face="Times New Roman" size="3">Svenskt Mästerskap i Programmering/Norgesmesterskapet 2002<br /></font></p><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 </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />using namespace std;<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">const</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> INF </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">28</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"> d[</span><span style="COLOR: #000000">11</span><span style="COLOR: #000000">][</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"> sum(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> j) {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> ret </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">, k;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i; k</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">j; k</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">) ret </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> k;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    return ret;<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" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> max(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> a, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> b) {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    return a </span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> b ? a : b;<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" /><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"> main() {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> caseTime; <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i, j, k, t, K, M, l;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    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">caseTime);<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">while</span><span style="COLOR: #000000"> (caseTime</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">) {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />        scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">K, </span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">M);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (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">M; i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">) {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />            </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i; j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">M; j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">) {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                d[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][i][j] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> sum(i, j);<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" />        }<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">; k</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">K; k</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">) {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />            </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (l</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; l</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">M; l</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">) {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">; i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">l</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">M; i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">) {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                    j </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> i </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> l;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (i </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> j) {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                        d[k][i][j] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> i;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                        continue;<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" />                    d[k][i][j] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> INF;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (t</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i; t</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">j; t</span><span style="COLOR: #000000">++</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"> tmp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (t </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> i) tmp </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> d[k][i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                        </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (t </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> j) tmp </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> d[k</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][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/None.gif" align="top" />                        </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> tmp </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> max(d[k</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][i][t</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">], d[k</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][t</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j]);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                        tmp </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> max(d[k</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][i][t</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">], d[k][t</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j]);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (d[k][i][j] </span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> t </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> tmp) d[k][i][j] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> t </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> tmp;<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" />                }<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" />        }<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />        printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, d[K][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][M]);<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" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    return </span><span style="COLOR: #000000">0</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/qywyh/aggbug/20583.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-03-26 00:41 <a href="http://www.cppblog.com/qywyh/articles/20583.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku 2486 树状dp</title><link>http://www.cppblog.com/qywyh/articles/18618.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Sat, 10 Feb 2007 10:55:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/18618.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/18618.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/18618.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/18618.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/18618.html</trackback:ping><description><![CDATA[
		<p align="center">
				<font color="blue" size="5">Apple Tree</font>
				<br />Time Limit:1000MS  Memory Limit:65536K<br />Total Submit:541 Accepted:148 </p>
		<p>
				<font color="blue" size="5">Description</font>
				<br />
				<font face="Times New Roman" size="3">Wshxzt is a lovely girl. She likes apple very much. One day HX takes her to an apple tree. There are N nodes in the tree. Each node has an amount of apples. Wshxzt starts her happy trip at one node. She can eat up all the apples in the nodes she reaches. HX is a kind guy. He knows that eating too many can make the lovely girl become fat. So he doesn’t allow Wshxzt to go more than K steps in the tree. It costs one step when she goes from one node to another adjacent node. Wshxzt likes apple very much. So she wants to eat as many as she can. Can you tell how many apples she can eat in at most K steps.</font>
		</p>
		<p>
				<font color="blue" size="5">Input</font>
				<br />
				<font face="Times New Roman" size="3">There are several test cases in the input <br />Each test case contains three parts. <br />The first part is two numbers N K, whose meanings we have talked about just now. We denote the nodes by 1 2 ... N. Since it is a tree, each node can reach any other in only one route. (1&lt;=N&lt;=100, 0&lt;=K&lt;=200) <br />The second part contains N integers (All integers are nonnegative and not bigger than 1000). The ith number is the amount of apples in Node i. <br />The third part contains N-1 line. There are two numbers A,B in each line, meaning that Node A and Node B are adjacent. <br />Input will be ended by the end of file. <br /><br />Note: Wshxzt starts at Node 1.</font>
		</p>
		<p>
				<font color="blue" size="5">Output</font>
				<br />
				<font face="Times New Roman" size="3">For each test case, output the maximal numbers of apples Wshxzt can eat at a line.</font>
		</p>
		<p>
				<font color="blue" size="5">Sample Input</font>
				<br />
				<font face="Times New Roman" size="3">
						<pre>2 1 
0 11
1 2
3 2
0 1 2
1 2
1 3
</pre>
				</font>
		</p>
		<p>
		</p>
		<p>
				<font color="blue" size="5">Sample Output</font>
				<br />
				<font face="Times New Roman" size="3">
						<pre>11
2
</pre>
				</font>
		</p>
		<p>
		</p>
		<p>
				<font color="blue" size="5">Source</font>
				<br />
				<font face="Times New Roman" size="3">POJ Contest,Author:magicpig@ZSU<br /><br /><br /></font>
		</p>
		<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 </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">iostream</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />using namespace std;<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">const</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> N </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">210</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"> adj[N][N];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> n, k;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> w[N];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> go[N][N], bk[N][N];<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">void</span>
				<span style="COLOR: #000000"> solve();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> dfs(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> dp(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000">);<br /><img id="Codehighlighter1_204_229_Open_Image" onclick="this.style.display='none'; Codehighlighter1_204_229_Open_Text.style.display='none'; Codehighlighter1_204_229_Closed_Image.style.display='inline'; Codehighlighter1_204_229_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_204_229_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_204_229_Closed_Text.style.display='none'; Codehighlighter1_204_229_Open_Image.style.display='inline'; Codehighlighter1_204_229_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />inline </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> max(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> a, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> b) </span>
				<span id="Codehighlighter1_204_229_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_204_229_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> a </span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> b </span>
						<span style="COLOR: #000000">?</span>
						<span style="COLOR: #000000"> a : b;<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 src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main()<br /><img id="Codehighlighter1_243_310_Open_Image" onclick="this.style.display='none'; Codehighlighter1_243_310_Open_Text.style.display='none'; Codehighlighter1_243_310_Closed_Image.style.display='inline'; Codehighlighter1_243_310_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_243_310_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_243_310_Closed_Text.style.display='none'; Codehighlighter1_243_310_Open_Image.style.display='inline'; Codehighlighter1_243_310_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_243_310_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_243_310_Open_Text">
						<span style="COLOR: #000000">{<br /><img id="Codehighlighter1_283_297_Open_Image" onclick="this.style.display='none'; Codehighlighter1_283_297_Open_Text.style.display='none'; Codehighlighter1_283_297_Closed_Image.style.display='inline'; Codehighlighter1_283_297_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_283_297_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_283_297_Closed_Text.style.display='none'; Codehighlighter1_283_297_Open_Image.style.display='inline'; Codehighlighter1_283_297_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">while</span>
						<span style="COLOR: #000000"> (scanf(</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">%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">!=</span>
						<span style="COLOR: #000000"> EOF) </span>
						<span id="Codehighlighter1_283_297_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_283_297_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        solve();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </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" />
						<br />
						<img id="Codehighlighter1_326_666_Open_Image" onclick="this.style.display='none'; Codehighlighter1_326_666_Open_Text.style.display='none'; Codehighlighter1_326_666_Closed_Image.style.display='inline'; Codehighlighter1_326_666_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_326_666_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_326_666_Closed_Text.style.display='none'; Codehighlighter1_326_666_Open_Image.style.display='inline'; Codehighlighter1_326_666_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"> solve() </span>
				<span id="Codehighlighter1_326_666_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_326_666_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i, j, l;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> x, y;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img id="Codehighlighter1_376_418_Open_Image" onclick="this.style.display='none'; Codehighlighter1_376_418_Open_Text.style.display='none'; Codehighlighter1_376_418_Closed_Image.style.display='inline'; Codehighlighter1_376_418_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_376_418_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_376_418_Closed_Text.style.display='none'; Codehighlighter1_376_418_Open_Image.style.display='inline'; Codehighlighter1_376_418_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (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">n; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">) </span>
						<span id="Codehighlighter1_376_418_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_376_418_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        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">w[i]);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        adj[i][</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img id="Codehighlighter1_444_526_Open_Image" onclick="this.style.display='none'; Codehighlighter1_444_526_Open_Text.style.display='none'; Codehighlighter1_444_526_Closed_Image.style.display='inline'; Codehighlighter1_444_526_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_444_526_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_444_526_Closed_Text.style.display='none'; Codehighlighter1_444_526_Open_Image.style.display='inline'; Codehighlighter1_444_526_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (i</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">; 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">; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">) </span>
						<span id="Codehighlighter1_444_526_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_444_526_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        scanf(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">%d%d</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">, </span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000">x, </span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000">y);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        adj[x][</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">adj[x][</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">]] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> y;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        adj[y][</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">adj[y][</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">]] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> x;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    memset(go, </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">, sizeof(go));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    memset(bk, </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">, sizeof(bk));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    dfs(</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> ans </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> max(go[</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">][k], bk[</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">][k]);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    printf(</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">%d\n</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">, ans </span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000"> w[</span>
						<span style="COLOR: #000000">1</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" />
						<br />
						<img id="Codehighlighter1_693_989_Open_Image" onclick="this.style.display='none'; Codehighlighter1_693_989_Open_Text.style.display='none'; Codehighlighter1_693_989_Closed_Image.style.display='inline'; Codehighlighter1_693_989_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_693_989_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_693_989_Closed_Text.style.display='none'; Codehighlighter1_693_989_Open_Image.style.display='inline'; Codehighlighter1_693_989_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"> dfs(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> p, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> pp) </span>
				<span id="Codehighlighter1_693_989_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_693_989_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i, j, l;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> ts;    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img id="Codehighlighter1_750_987_Open_Image" onclick="this.style.display='none'; Codehighlighter1_750_987_Open_Text.style.display='none'; Codehighlighter1_750_987_Closed_Image.style.display='inline'; Codehighlighter1_750_987_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_750_987_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_750_987_Closed_Text.style.display='none'; Codehighlighter1_750_987_Open_Image.style.display='inline'; Codehighlighter1_750_987_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (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">adj[p][</span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">]; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">) </span>
						<span id="Codehighlighter1_750_987_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_750_987_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        ts </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> adj[p][i];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (ts </span>
								<span style="COLOR: #000000">==</span>
								<span style="COLOR: #000000"> pp) </span>
								<span style="COLOR: #0000ff">continue</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        dfs(ts, p);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        bk[ts][</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        bk[ts][</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        go[ts][</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000"> (l</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">k; l</span>
								<span style="COLOR: #000000">&gt;=</span>
								<span style="COLOR: #000000">2</span>
								<span style="COLOR: #000000">; l</span>
								<span style="COLOR: #000000">--</span>
								<span style="COLOR: #000000">) bk[ts][l] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> bk[ts][l</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"> w[ts];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000"> (l</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">k; l</span>
								<span style="COLOR: #000000">&gt;=</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">; l</span>
								<span style="COLOR: #000000">--</span>
								<span style="COLOR: #000000">) go[ts][l] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> go[ts][l</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"> w[ts];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        dp(p, ts);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</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" />
						<br />
						<img id="Codehighlighter1_1014_1397_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1014_1397_Open_Text.style.display='none'; Codehighlighter1_1014_1397_Closed_Image.style.display='inline'; Codehighlighter1_1014_1397_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_1014_1397_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1014_1397_Closed_Text.style.display='none'; Codehighlighter1_1014_1397_Open_Image.style.display='inline'; Codehighlighter1_1014_1397_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"> dp(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> x, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> y) </span>
				<span id="Codehighlighter1_1014_1397_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_1014_1397_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i, j, l;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> t1[N], t2[N];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    memset(t1, </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">, sizeof(t1));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    memset(t2, </s