@Lucifier: Thanks a lot.. But,I am able to follow the code that u posted for Non-Decreasing Digits. Can u jus explain ur algo instead of givin the code directly? Thanks once again.
On Tue, Dec 27, 2011 at 10:44 PM, Lucifer <[email protected]> wrote: > @ Special Nos.. > Well the actual logic would be : > int count = 0;for ( int i = 2; i <= LOGbase2(N) ; i+=2) count+= > [ (i-1) C (i/2) ] ; // here xCy is nothing but the no. of ways y items > can be selected from a collection of x items. > Hence, the working code: > int totalCount = 0; > int interCnt = 1; > > if ( LOGbase2(N) > 1) > { > totalCount = 1; // for LOGbase2(N) = 2... > > for ( int i = 4; i <= LOGbase2(N) ; i+=2) > { > interCnt = (i-1)*(i-2) * interCnt / ( i/2 * (i/2 -1)); > totalCount += interCnt; > > } > printf("%d", totalCount); > } > else > printf("%d", 0); > On Dec 27, 7:38 pm, Tasvinder Singh <[email protected]> wrote: >> I think the first problem involves some mathematics... >> In this we fix the first bit and if the remaining no. of bits are odd then >> we calculate the no. as follows >> >> If we have 2^4=16 then total bits 5 so we do not include this. >> Total no. of bits in one less than the given no. (in this eg. 15) is 4. >> Fix first bit, no. of bits remaining = 3 >> Now let 2 bits are 0 and one bit 1. We have total 3!/(2!*1!) = 3 >> combinations. >> >> Now go for next even no which is 2 in this case again do the same >> Fix first bit, no. of bits remaining = 1 >> Now let 1 bit is 0. We have total 1!/(0!*1!) = 1 combinations. >> >> Next even 0. stop here. >> You can go for this by starting from 2 till no. is less than given N >> >> >> >> >> >> >> >> >> >> On Tue, Dec 27, 2011 at 7:28 PM, kumar rajat <[email protected]> wrote: >> > Hi >> > I have jus started to learn DP and I have coded the standard >> > algorithms(LCS,etc). >> > I have been trying these problems in SPOJ: >> >> >http://www.spoj.pl/problems/NOVICE63/ >> >http://www.spoj.pl/problems/NY10E/ >> >> > I understand these may be solved elegantly using DP,but I dont get to >> > code the same. >> > Can any1 help me how to solve these types of problems using DP? >> > Any help regarding the same will be greatly appreciated. >> >> > -- >> > You received this message because you are subscribed to the Google Groups >> > "Algorithm Geeks" group. >> > To post to this group, send email to [email protected]. >> > To unsubscribe from this group, send email to >> > [email protected]. >> > For more options, visit this group at >> >http://groups.google.com/group/algogeeks?hl=en. >> >> -- >> Tasvinder Singh >> B.Tech Final Year, >> Department of Computer Engineering, >> Malaviya National Institute Of Technology, Jaipur. >> Contact: +91-9460627331 > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
