@All

As i see this question is more about the size of code than runtime..
Hence, my next post might not help a lot on the front of size but may
help in case u look at runtime.. If not of interest plz do skip this
post..

// M muls...

int a=2*m-1; b=m/2, k=m/2; while(--k)  { b*=k; a*=(a-2); a-
=2;} printf("%d", a*pow(2, (m+1)/2) / b);


On Dec 16, 6:39 pm, Lucifer <sourabhd2...@gmail.com> wrote:
> @above
> Correction.. its 2m C m
>
> @saurabh..
> Sorry i missed your post.. seems that u are doing exactly the same..
>
> Just a suggestion.. to make the code run faster, we can store f(n) in
> a variable and then use it in the expression to avoid recalculation
> of !(n)
> i,e t = f(m);
> printf("%d",  f(2*m) / pow(t,2) );
> //In the original code we are making 4m multiplications.. in the above
> given one we are doing 3m multiplcations..
>
> We can further optimize (2m muls and m adds)..
>
> Further optimization could be:
> int a=2*m; b=m, k=m;
> while(--k)
> { b*=k; a*=(k+m);}
> printf("%d", a/b);
>
> On Dec 16, 6:14 pm, Lucifer <sourabhd2...@gmail.com> wrote:
>
>
>
>
>
>
>
> > @anubhav..
>
> > Its 2n C n...
>
> > Basically they are asking u to finds no. of paths that can be formed
> > using m Tops and m rights..which is nothing but no. of unique ways of
> > arranging m T's and m R's .. i,e 2n C n
>
> > On Dec 16, 5:38 pm, sourabh singh <singhsourab...@gmail.com> wrote:
>
> > > limit is just v.smll can ny1 help me with this code: [ c code ] get it
> > > under 120 bytes .
> > > is there any way to take inputs. without using scanf ???   in c .  m
> > > thinking about inputs getting into
> > > argc array directly.???
>
> > > #define s(n) scanf("%d",&n);
> > > f(int n){return n==1?1:(n*f(n-1));}
> > > main()
> > > {
> > >       int t,n;
> > >       s(t)
> > >       while(t--)
> > >       {         s(n)
> > >                 printf("%d",(f(2*n)/f(n))/f(n));
> > >       }
>
> > > }
> > > On Thu, Dec 15, 2011 at 10:08 PM, anubhav raj <anubhaw....@gmail.com> 
> > > wrote:
> > > > #include<stdio.h>
> > > > #define s(n) scanf("%d",&n)
> > > > #define I int
> > > > I a[14][14];
> > > > I d(I m,I n)
> > > > {
> > > > I s=a[m][n];
> > > > I k;
> > > > if(!m||!n)
> > > > k=1;
> > > > else if(s)
> > > > k=s;
> > > > else
> > > > {
> > > > k=d(m-1,n)+d(m,n-1);
> > > > s=k;
> > > > }
> > > > return k;
> > > > }
> > > > main()
> > > > {
> > > > I t,n,k;s(t);
> > > > while(t--)
> > > > {
> > > > s(n);
> > > > k=d(n,n);
> > > > printf("%d\n",k);
> > > > }
> > > > }
>
> > > > @saurav:this is the actual and very simple code...........may be u cn
> > > > reduce its no of bytes........its simple dp approach...tnx....
>
> > > > --
> > > > You received this message because you are subscribed to the Google 
> > > > Groups
> > > > "Algorithm Geeks" group.
> > > > To post to this group, send email to algogeeks@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > algogeeks+unsubscr...@googlegroups.com.
> > > > 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to