zoukankan      html  css  js  c++  java
  • poj2192

    初看这道题,以为是先用SA和SC求LCS,再从SC中把SA剔除,看剩下来的是不是SB(……)

    显然不对;因为SC与SA的公共子串不止一种,判断不一定正确。

    于是考虑SC中每一个字符,如果能够匹配,那么不是SA中的就是SB中的;

    定义bool s[i,j]为SA前i个,SB前j个能否组成SC前i+j个;

    所以s[i,j]=true (s[i-1,j] and SA[i]=s[i+j]) or (s[i,j-1] and SB[j]=s[i+j]);

    则最后能匹配的条件为s[length(SA),length(SB)]=true

     1 var f:array[0..500,0..500] of boolean;
     2     ff:array[0..500] of boolean;
     3     xx,s1,s2,s3:ansistring;
     4     l1,l2,l3,k,i,j,p,n,x,y:integer;
     5     check:boolean;
     6 function max(a,b:integer):integer;
     7   begin
     8     if a>b then max:=a else max:=b;
     9   end;
    10 
    11 begin
    12   readln(n);
    13   for k:=1 to n do
    14   begin
    15     readln(xx);
    16     xx:=xx+' ';
    17     p:=pos(' ',xx);
    18     s1:=copy(xx,1,p-1);
    19     xx:=copy(xx,p+1,length(xx));
    20     p:=pos(' ',xx);
    21     s2:=copy(xx,1,p-1);
    22     xx:=copy(xx,p+1,length(xx));
    23     p:=pos(' ',xx);
    24     s3:=copy(xx,1,p-1);
    25     fillchar(f,sizeof(f),false);
    26     l1:=length(s1);
    27     l2:=length(s2);
    28     l3:=length(s3);
    29     f[0,0]:=true;
    30     if s1[1]=s3[1] then f[1,0]:=true;
    31     if s2[1]=s3[1] then f[0,1]:=true;
    32     for i:=0 to l1 do
    33       for j:=0 to l2 do
    34       begin
    35         if (s1[i]=s3[i+j]) and f[i-1,j] then f[i,j]:=true;
    36         if (s2[j]=s3[i+j]) and f[i,j-1] then f[i,j]:=true;
    37       end;
    38     if f[l1,l2] then writeln('Data set ',k,': yes')
    39     else writeln('Data set ',k,': no');
    40   end;
    41 end.
    View Code
  • 相关阅读:
    cent os 6.8 php 5.6 安装ffmpeg扩展
    Linux查找目录下文件包含关键字
    python生成随机验证码
    zabbix添加任务计划和sshd文件修改key
    OS模块
    python模块
    python内建函数
    python3 爬煎蛋ooxx妹子图
    ssm整合-Sping整合Mybatis框架配置事务07
    ssm整合-Sping整合Mybatis框架06
  • 原文地址:https://www.cnblogs.com/phile/p/4473311.html
Copyright © 2011-2022 走看看