Re: [algogeeks] Re: how to optimally compute a matrix (nXn) to the power of k?

2011-07-19 Thread Rishabh Maurya
You can try like this #include stdio.h #include string.h #define N 3 void copy(int A[N][N],int B[N][N]) { int i,j; for(i=0;iN;i++) for(j=0;jN;j++) A[i][j]=B[i][j]; } void mul(int A[N][N],int B[N][N],int M[N][N]) { int i,j,k; for(i=0;iN;i++)

Re: [algogeeks] Re: how to optimally compute a matrix (nXn) to the power of k?

2011-07-19 Thread Rishabh Maurya
time complexity is (cost of multiplication)*log(n) -- 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

Re: [algogeeks] Re: how to optimally compute a matrix (nXn) to the power of k?

2011-07-19 Thread Rishabh Maurya
Yes its running fine at gcc 4.3.2 . And it might show warning in that case just change the name of the function exp(). -- 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

Re: [algogeeks] Re: how to optimally compute a matrix (nXn) to the power of k?

2011-07-19 Thread Rishabh Maurya
Yes sure , we know if A B C are matrices of same dimension then Ax(BxC)=(AxB)xC So now what SAMM is saying i.e normal exponential of any number can be applied in case of matrix expo too and the same thing I too did but using loop without recursive fashion. I hope its clear now . -- You

Re: [algogeeks] MS

2011-07-19 Thread Rishabh Maurya
Better go through following link , its explained nicely their. http://www.ihas1337code.com/2011/01/find-k-th-smallest-element-in-union-of.html -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] X-AmazoN

2011-07-15 Thread Rishabh Maurya
I don't think so that probability would be exact 1/1000 . suppose number is ( a9 a8 a7 a6 a5 a4 a3 a2 a1 a0) where a0 is least and a9 is most significant bit then you can generate each of the bit ai using given bit generator but if but at a time (a9 , a8 , a7 , a6 , a5 , a3 ) and any other bit

Re: [algogeeks] X-AmazoN

2011-07-15 Thread Rishabh Maurya
but suppose you have to generate numbers between [1,513] then also it would generate numbers them each with probability 1/1024 which could make a big difference and I feel the above solution to be incorrect . May be we could think of a better one . -- You received this message because you are

Re: [algogeeks] X-AmazoN

2011-07-15 Thread Rishabh Maurya
@Surender Your solution in correct one . -- 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.

Re: [algogeeks] Counting the ways.

2011-07-14 Thread Rishabh Maurya
It can be done in O(2^n) -- 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,

Re: [algogeeks] Puzzle

2011-05-27 Thread Rishabh Maurya
suppose bottom 4 teams have won least matches and upper 4 teams have won equal number of matches ... 1 - x 2 - x 3 - x 4 - x 5 - 6 6 - 4 7 - 2 8 - 0 total matches are 56 and let upper four teams have won x matches each so x = (56-(6+4+2+0))/4 x = 11 so in this way to ensure qualification

Re: [algogeeks] Re: Puzzle

2011-05-27 Thread Rishabh Maurya
No , you are wrong .. problem statement says how many matches should a teams win to ensure its qualification , their no word like minimum or maximum ... 8 gets wrong if following situation arises 1 - 9 2 - 9 3 - 9 4 - 9 5 - 8 6 - 6 7 - 4 8 - 2 -- You received this message because you are