Title Description: http://poj.org/problem?id=2192
Problem solving ideas;
1.BOOK[I][J] Indicates whether the first element of STR2 and the first J elements of STR1 can make up an array of Str_link's former (i+j) elements;
If yes, then book[i][j]=1, otherwise, book[i][j]=0;
2.BOOK[0][J] Indicates whether the first J elements of str1 can form an array of Str_link's former J elements;
Book[i][0] Indicates whether the first I element of str2 can make up an array of the first I elements of the str_link;
3. State transition equation:
if (!book[i-1][j]&&!book[i][j-1]) continue;
if (Book[i-1][j]&&str2[i]==str_link[i+j]) book[i][j]=1;
if (Book[i][j-1]&&str1[j]==str_link[i+j]) book[i][j]=1;
Example Analysis:
str1:47935 str2:25645439 str_link:2564745934359
Initial state of book:
The book after relaxation:
AC Code:
1#include <stdio.h>2#include <string.h>3 4 Charstr1[202],str2[202];5 Charstr_link[404];6 7 intbook[202][202];8 intStl1,stl2;9 Ten voidGet_book ()//Initialize Book One { A - inti; - theStl1=strlen (str1+1); -Stl2=strlen (str2+1); - - for(i=1; i<=stl1;i++) + { - + if(book[0][i-1]&&str1[i]==str_link[i]) book[0][i]=1; A Else Break; at - } - - for(i=1; i<=stl2;i++) - { - in if(book[i-1][0]&&str2[i]==str_link[i]) book[i][0]=1; - Else Break; to + } - the * } $ Panax Notoginseng intMain () - { the + intT,count=0; A inti,j; the +scanf"%d",&T); - $ while(t--){ $ -count++; -memset (book,0,sizeof(book)); the -book[0][0]=1;Wuyi thescanf"%s%s%s", str1+1, str2+1, str_link+1); - Wu Get_book (); - About for(i=1; i<=stl2;i++) $ { - - for(j=1; j<=stl1;j++) - { A + if(!book[i-1][j]&&!book[i][j-1])Continue; the - if(book[i-1][J]&&STR2[I]==STR_LINK[I+J]) book[i][j]=1; $ the if(book[i][j-1]&&STR1[J]==STR_LINK[I+J]) book[i][j]=1; the the } the - } in the if(BOOK[STL2][STL1]) printf ("Data Set%d:yes\n", count); the Elseprintf"Data Set%d:no\n", Count); About the } the the return 0; + - } the Bayi /* the the 1 - - 47935 the the 25645439 the the 2564745934359 - the the */
View Code
Test data:
DP Practice Poj2192 Zipper