mufasa's blog

By mufasa, 11 years ago, In English

Hi i am trying to solve this problem.. http://community.topcoder.com/stat?c=problem_statement&pm=1215&rd=4555

my code is :

public static int  ColorMe(int i,int j,char color) {
		int ti = i,tj = j;
		if(i>j || i>count || j>count){
			return 0;
		}
	        if(m[i][j]<infy ) return m[i][j];
		if(i==j) {
			m[i][i] =  color==arr[i]?0:1;
			return m[i][i];
		}
		for(int t=i;t<=j&&i<j;t++) {
			if(color == arr[i]){
				i++;//to get the next stripe not in proper color
			}
			if(color == arr[j]){
				
				j--;//to get the next stripe not in proper color
			}
		}
		for(int k=i;k<=j;k++) {
			m[ti][tj] = min(m[ti][tj],ColorMe(i,k, arr[i]) + 1+ (k==j?0: (ColorMe(k+1,j,color))));
		}
		return m[ti][tj];
		
	}

I am getting wrong answer for the last test case.. Please point out what is wrong in it. ColorMe(i,j,col): stripes i to j are in having color = col.

Full text and comments »

Tags dp
  • Vote: I like it
  • 0
  • Vote: I do not like it

By mufasa, 11 years ago, In English

Hi i want to solve this problem using Dynamic programming. Please provide some hint Problem: http://topcoder.bgcoder.com/print.php?id=596

Full text and comments »

Tags dp
  • Vote: I like it
  • 0
  • Vote: I do not like it

By mufasa, 13 years ago, In English

How many unique cycles of length 4 present in a complete Undirected graph of 6 vertices? My answer is 45 and i think its not correct because there are only 4 options 1)15 2)30 3)90 4)360 please share your view

Full text and comments »

  • Vote: I like it
  • -18
  • Vote: I do not like it

By mufasa, 13 years ago, In English
Can anybody suggest me optimal substructure for the above problem.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By mufasa, 13 years ago, In English

Want to factorize 15 digit number.I have implemented the fermat's thm but it is not suitable for numbers having factor not close to square root of that number .Suggest me some methods .Thanx

Full text and comments »

  • Vote: I like it
  • +8
  • Vote: I do not like it