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.

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