mshubham's blog

By mshubham, 12 years ago, In English

I am getting wrong answer with space optimization technique

Here is my code

int main(){
	int test;
	for(scanf("%d",&test);test>0;test--){
		char str1[6110];
		char str2[6110];
		scanf("%s",str1);
		int l=strlen(str1);
		for(int i=0;i<l;i++) str2[i]=str1[l-i-1];
		int L[3][6110];
		int tmp=1;
		memset(L,0,sizeof L);
		for(int i=1;i<=l;++i){
			for(int j=1;j<=l;++j){
				if(str1[i-1]==str2[j-1]) L[tmp][j]=1+L[!tmp][j];
				else L[tmp][j]=max(L[tmp][j-1],L[!tmp][j]);
			}
			tmp=!tmp;
		}
		int ans=l-L[!tmp][l];
		printf("%d\n",ans);
	}
	return 0;
}

Full text and comments »

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

By mshubham, 12 years ago, In English

Can anyone help me to solve this problem

CONSTELLATIONS

Thanks

Full text and comments »

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

By mshubham, 13 years ago, In English

Please Help to solve these SPOJ Problems

Make Them Equal

Update The Array !

Full text and comments »

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

By mshubham, 13 years ago, In English
  1. Can anyone provide me the implementation and tutorial on Aho Corasick algorithms and some problems containing aho corasick algorithm.

  2. An algorithm to generate a random unsolved Sudoku whose only a unique solution exist.

  3. Find the dividend

Full text and comments »

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

By mshubham, 13 years ago, In English

You are given n strings and you have to arrange anagram strings in separate line in order. for example:

Input:

n = 7

aabbcc

acbabc

abccba

bcba

ab

aa

abbc

Output:

aa

aabbcc abccba acbabc

ab

abbc bcba

Explanation: output strings in same lines are anagram in Lexicographically order also strings in different lines are also Lexicographically arranged.

I am trying to solve the problem but my code showing runtime error

here is my code: Anagrams

please help

Full text and comments »

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

By mshubham, 13 years ago, In English

Source: Mathalon

Given ai,bi belongs to set {1,2,3,4,5,6,7,8,9,0}

Find the Number of different solution for N=10 such that a1+a2+..aN=b1+b2+..bN=k and k takes all value 0<=k<=9N

Example N=1 for each 0<=k<=9 we have one solution so the answer is 10

Can anyone solve this problem ?

Full text and comments »

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

By mshubham, 13 years ago, In English

Infinite Sum

Can anyone explain the solution.. solution are posted on homepage, but it seems difficult to understand.

Full text and comments »

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