<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: To the Programmers..</title>
	<atom:link href="http://www.lnexun.com/2008/12/to-programmers/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lnexun.com/2008/12/to-programmers/</link>
	<description>Natural Log of Exun</description>
	<lastBuildDate>Sat, 24 Dec 2011 16:16:43 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: <img src='http://www.lnexun.com/wp-content/plugins/rpx/images/google.png'/> ambarpal1996</title>
		<link>http://www.lnexun.com/2008/12/to-programmers/comment-page-1/#comment-26132</link>
		<dc:creator><img src='http://www.lnexun.com/wp-content/plugins/rpx/images/google.png'/> ambarpal1996</dc:creator>
		<pubDate>Sun, 03 Jul 2011 08:36:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.lnexun.com/wordpress/2008/12/to-programmers.html#comment-26132</guid>
		<description>So the final code is this:
#include
#include
using namespace std;
int max(int x,int y)
{
	if (x&gt;y)
	{return x;}
	else
	{return y;}
}


int main()
{
	int a[100000],s[100000],n=0,ans=0;
	cin&gt;&gt;n;
	for (int init=0;init&lt;100000;init++){
		a[init]=0;
		s[init]=0;
	}
	for (int num=0;num&gt;a[num];
	}
	s[0]=a[0];
	s[1]=max(a[0],a[1]);
	for (num=2;num&lt;n;num++){
		s[num]=max(a[num]+s[num-2],s[num-1]);
	}
	cout&lt;&lt;s[num-1];
	getch();
	return 0;
}</description>
		<content:encoded><![CDATA[<p>So the final code is this:<br />
#include<br />
#include<br />
using namespace std;<br />
int max(int x,int y)<br />
{<br />
	if (x>y)<br />
	{return x;}<br />
	else<br />
	{return y;}<br />
}</p>
<p>int main()<br />
{<br />
	int a[100000],s[100000],n=0,ans=0;<br />
	cin>>n;<br />
	for (int init=0;init&lt;100000;init++){<br />
		a[init]=0;<br />
		s[init]=0;<br />
	}<br />
	for (int num=0;num>a[num];<br />
	}<br />
	s[0]=a[0];<br />
	s[1]=max(a[0],a[1]);<br />
	for (num=2;num<n;num++){<br />
		s[num]=max(a[num]+s[num-2],s[num-1]);<br />
	}<br />
	cout<<s[num-1];<br />
	getch();<br />
	return 0;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: &#34;Sajal&#34;</title>
		<link>http://www.lnexun.com/2008/12/to-programmers/comment-page-1/#comment-1645</link>
		<dc:creator>&#34;Sajal&#34;</dc:creator>
		<pubDate>Sun, 21 Dec 2008 13:21:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.lnexun.com/wordpress/2008/12/to-programmers.html#comment-1645</guid>
		<description>Yes, thats perfect!&lt;br /&gt;The trick is to use, what we call, &lt;b&gt;DYNAMIC PROGRAMMING (DP)&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;The way to approach the problem is as follows&lt;br /&gt;&lt;br /&gt;Consider a subsequence of numbers initially (basically subproblems), viz., &lt;br /&gt;&lt;br /&gt;Step 1&lt;br /&gt;We just have 30&lt;br /&gt;So the best possible is 30 (call it step1_max)&lt;br /&gt;&lt;br /&gt;Step 2&lt;br /&gt;We have 30 &amp; 10&lt;br /&gt;So the best possible is still 30(step2_max)&lt;br /&gt;&lt;br /&gt;Step 3&lt;br /&gt;We have 30 , 10 , 8&lt;br /&gt;So the best possible is (8+step1_max) OR step2_max&lt;br /&gt;Compare and store the answer as step3_max (here its 30+8=38)&lt;br /&gt;&lt;br /&gt;Step 4&lt;br /&gt;we have 30, 10 ,8, 20&lt;br /&gt;20+step2_max or step_3 max&lt;br /&gt;=step4_max=50&lt;br /&gt;&lt;br /&gt;We proceed further in the similar manner&lt;br /&gt;For the algorithm you can have a look at Aman&#039;s comment.&lt;br /&gt;&lt;br /&gt;I will post a little more about dynamic programming soon.</description>
		<content:encoded><![CDATA[<p>Yes, thats perfect!<br />The trick is to use, what we call, <b>DYNAMIC PROGRAMMING (DP)</b>.</p>
<p>The way to approach the problem is as follows</p>
<p>Consider a subsequence of numbers initially (basically subproblems), viz., </p>
<p>Step 1<br />We just have 30<br />So the best possible is 30 (call it step1_max)</p>
<p>Step 2<br />We have 30 &amp; 10<br />So the best possible is still 30(step2_max)</p>
<p>Step 3<br />We have 30 , 10 , 8<br />So the best possible is (8+step1_max) OR step2_max<br />Compare and store the answer as step3_max (here its 30+8=38)</p>
<p>Step 4<br />we have 30, 10 ,8, 20<br />20+step2_max or step_3 max<br />=step4_max=50</p>
<p>We proceed further in the similar manner<br />For the algorithm you can have a look at Aman&#39;s comment.</p>
<p>I will post a little more about dynamic programming soon.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: aman</title>
		<link>http://www.lnexun.com/2008/12/to-programmers/comment-page-1/#comment-1644</link>
		<dc:creator>aman</dc:creator>
		<pubDate>Sun, 21 Dec 2008 11:38:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.lnexun.com/wordpress/2008/12/to-programmers.html#comment-1644</guid>
		<description>sajal bhaiyya, instead of using a function max, we can have an array max[] of size n in which the maximum value from 0 to i in array m[] can be stored.....whenever we get a new value in m[], max[] can be easily updated&lt;br /&gt;in short,&lt;br /&gt;max[o]=val[0]&lt;br /&gt;if (val[1]&gt;val[0])&lt;br /&gt;max[1]=val[1]&lt;br /&gt;else&lt;br /&gt;max[1]=val[0]&lt;br /&gt;now,&lt;br /&gt;for i=2 to n &lt;br /&gt;m[i]=val[i] + max[i-2]&lt;br /&gt;if (m[i]&gt;max[i-1])&lt;br /&gt;max[i]=m[i]&lt;br /&gt;else&lt;br /&gt;max[i]=max[i-1]  &lt;br /&gt;in the end print max[n]</description>
		<content:encoded><![CDATA[<p>sajal bhaiyya, instead of using a function max, we can have an array max[] of size n in which the maximum value from 0 to i in array m[] can be stored&#8230;..whenever we get a new value in m[], max[] can be easily updated<br />in short,<br />max[o]=val[0]<br />if (val[1]&gt;val[0])<br />max[1]=val[1]<br />else<br />max[1]=val[0]<br />now,<br />for i=2 to n <br />m[i]=val[i] + max[i-2]<br />if (m[i]&gt;max[i-1])<br />max[i]=m[i]<br />else<br />max[i]=max[i-1]  <br />in the end print max[n]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: aman</title>
		<link>http://www.lnexun.com/2008/12/to-programmers/comment-page-1/#comment-1643</link>
		<dc:creator>aman</dc:creator>
		<pubDate>Sun, 21 Dec 2008 10:51:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.lnexun.com/wordpress/2008/12/to-programmers.html#comment-1643</guid>
		<description>i dunt think i got ur question rishab...i m storin the max value for every location from 0 to n-1</description>
		<content:encoded><![CDATA[<p>i dunt think i got ur question rishab&#8230;i m storin the max value for every location from 0 to n-1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: &#34;Sajal&#34;</title>
		<link>http://www.lnexun.com/2008/12/to-programmers/comment-page-1/#comment-1642</link>
		<dc:creator>&#34;Sajal&#34;</dc:creator>
		<pubDate>Sat, 20 Dec 2008 18:16:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.lnexun.com/wordpress/2008/12/to-programmers.html#comment-1642</guid>
		<description>I don&#039;t think you&#039;ll be able to get the answer this way.</description>
		<content:encoded><![CDATA[<p>I don&#8217;t think you&#8217;ll be able to get the answer this way.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rishabh</title>
		<link>http://www.lnexun.com/2008/12/to-programmers/comment-page-1/#comment-1641</link>
		<dc:creator>Rishabh</dc:creator>
		<pubDate>Sat, 20 Dec 2008 17:43:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.lnexun.com/wordpress/2008/12/to-programmers.html#comment-1641</guid>
		<description>im pretty close to getting the answer. basically what im doing is first sorting them and then manipulating them. i have used a made-up method to ensure that they are not next to each other and that is what has a couple of small flaws in it.</description>
		<content:encoded><![CDATA[<p>im pretty close to getting the answer. basically what im doing is first sorting them and then manipulating them. i have used a made-up method to ensure that they are not next to each other and that is what has a couple of small flaws in it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: &#34;Sajal&#34;</title>
		<link>http://www.lnexun.com/2008/12/to-programmers/comment-page-1/#comment-1640</link>
		<dc:creator>&#34;Sajal&#34;</dc:creator>
		<pubDate>Sat, 20 Dec 2008 17:29:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.lnexun.com/wordpress/2008/12/to-programmers.html#comment-1640</guid>
		<description>The solution is correct if it had the condition been n&lt;=1000 but the program wont work for n=100000&lt;br /&gt;&lt;br /&gt;Aman, your solution is an order n*n method so the time &amp; other constraints wont permit it&lt;br /&gt;&lt;br /&gt;What i want you is to think more innovatively and to reduce the amount of work the CPU has to do.&lt;br /&gt;&lt;br /&gt;Develop on the method you have provided. Its very close to the ideal solution.</description>
		<content:encoded><![CDATA[<p>The solution is correct if it had the condition been n&lt;=1000 but the program wont work for n=100000</p>
<p>Aman, your solution is an order n*n method so the time &amp; other constraints wont permit it</p>
<p>What i want you is to think more innovatively and to reduce the amount of work the CPU has to do.</p>
<p>Develop on the method you have provided. Its very close to the ideal solution.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rishabh</title>
		<link>http://www.lnexun.com/2008/12/to-programmers/comment-page-1/#comment-1638</link>
		<dc:creator>Rishabh</dc:creator>
		<pubDate>Sat, 20 Dec 2008 16:39:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.lnexun.com/wordpress/2008/12/to-programmers.html#comment-1638</guid>
		<description>aman your thing would be rather incomplete right? cause, yours takes in every alternate lpcation of the array, but what if, like in the example, you have to take every third or maybe a third then a second?</description>
		<content:encoded><![CDATA[<p>aman your thing would be rather incomplete right? cause, yours takes in every alternate lpcation of the array, but what if, like in the example, you have to take every third or maybe a third then a second?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aditya</title>
		<link>http://www.lnexun.com/2008/12/to-programmers/comment-page-1/#comment-1637</link>
		<dc:creator>Aditya</dc:creator>
		<pubDate>Sat, 20 Dec 2008 13:59:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.lnexun.com/wordpress/2008/12/to-programmers.html#comment-1637</guid>
		<description>Interesting question. Has this been taken from the online programming olympiad thing?&lt;br /&gt;&lt;br /&gt;~AA</description>
		<content:encoded><![CDATA[<p>Interesting question. Has this been taken from the online programming olympiad thing?</p>
<p>~AA</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: aman</title>
		<link>http://www.lnexun.com/2008/12/to-programmers/comment-page-1/#comment-1636</link>
		<dc:creator>aman</dc:creator>
		<pubDate>Sat, 20 Dec 2008 12:35:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.lnexun.com/wordpress/2008/12/to-programmers.html#comment-1636</guid>
		<description>we can proceed by storing the maximum number of chocolates one can have at position i in an array of size N....then v can find the maximum in that array&lt;br /&gt;this can be done by,&lt;br /&gt;first accept the no. of chocolates in each basket in array v[]&lt;br /&gt;then for i=0 to n&lt;br /&gt;m[i]=v[i] + max(i-2)&lt;br /&gt;at the end return max of all values in array m[]&lt;br /&gt;here max is a function that returns maximum of array m[] from index 0 to i-2 (not i-1 as then it will become consecutive)</description>
		<content:encoded><![CDATA[<p>we can proceed by storing the maximum number of chocolates one can have at position i in an array of size N&#8230;.then v can find the maximum in that array<br />this can be done by,<br />first accept the no. of chocolates in each basket in array v[]<br />then for i=0 to n<br />m[i]=v[i] + max(i-2)<br />at the end return max of all values in array m[]<br />here max is a function that returns maximum of array m[] from index 0 to i-2 (not i-1 as then it will become consecutive)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

