1. 程式人生 > >hdu 6170

hdu 6170

size const 思路 hdu strlen div sin clu blog

題意:正則表達式匹配

思路:DP dp[i][j]表示b串中0~i與0~j是否可以匹配,具體的轉移看代碼:

#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
const int maxn=2600;
char a[maxn],b[maxn];
bool dp[maxn][maxn];

int main()
{
    freopen("input.txt","r",stdin);
    int T;scanf("%d",&T);
    while(T--)
    {
        scanf(
"%s%s",a+1,b+1); memset(dp,0,sizeof dp); dp[0][0]=1; int sa=strlen(a+1),sb=strlen(b+1); for(int i=1;i<=sb;i++) { if(b[i]==*&&i>=2)dp[i][0]=dp[i-2][0]; for(int j=1;j<=sa;j++) { if(b[i]==a[j] || b[i]==
.)dp[i][j] = dp[i-1][j-1]; else if(b[i]==*) { dp[i][j] = dp[i-1][j] | dp[i-2][j]; dp[i][j] |= dp[i-1][j-1]&&(a[j]==a[j-1]); if(dp[i-1][j]) { while(j<=sa&&a[j]==a[j+1
])dp[i][++j]=1; } } } } if(dp[sb][sa]) printf("yes\n"); else printf("no\n"); } return 0; }

hdu 6170