1102 - } for(j=0; j<=ALP;j++){ tmp[i/2][j] =...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include<iostream> using namespace std; enum { SIZ = 1028, MAXV = 99999999, ALP = 'Z' - 'A' + 1, }; int num, len; char gen[SIZ][SIZ]; char ans[SIZ]; int tmp[SIZ][ALP+1]; i int compute(int p){ int i,j,l=num; for(i=0; i<num; i++){ for(j=0; j<ALP; j++){ tmp[i][j] = (gen[i][p]!=(j+'A')); } tmp[i][ALP] = 0; } while(l>1){ for(i=0; i<l; i+=2){ tmp[l][ALP] = MAXV; for(j=0; j<ALP; j++){ tmp[l][j] = tmp[i][j] + tmp[i+1][j]; // same // different int t=min(tmp[i][j]+tmp[i+1][ALP]+1,tmp[i][ALP]+tmp[i+1][j]+1); tmp[l][j] = min(t, tmp[l][j]); tmp[l][ALP] = min(tmp[l][ALP], tmp[l][j]);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } for(j=0; j&amp;lt;=ALP;j++){ tmp[i/2][j] = tmp[l][j]; } } l/=2; } for(i=0; i&amp;lt;ALP; i++){ if(tmp[0][i] == tmp[0][ALP]){ ans[p] = i + 'A'; } } return tmp[0][ALP]; } void fun(){ if(num == 1){ printf(&amp;quot;%s 0\n&amp;quot;, gen[0]); return; } int j, sum = 0; for(j=0; j&amp;lt;len; j++){ sum += compute(j); } ans[len] = 0; printf(&amp;quot;%s %d\n&amp;quot;, ans, sum); } int readIn(){ scanf(&amp;quot;%d%d&amp;quot;,&amp;amp;num, &amp;amp;len); for(int i=0; i&amp;lt;num; i++){ scanf(&amp;quot;%s&amp;quot;, gen[i]); } return num; } int main(){ while(readIn() &amp;gt; 0){ fun(); } return 0; }...
View Full Document

This note was uploaded on 02/18/2010 for the course CS 100 taught by Professor Acm during the Spring '10 term at Zhejiang University.

Page1 / 2

1102 - } for(j=0; j&amp;amp;amp;lt;=ALP;j++){ tmp[i/2][j] =...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online