hdu6170(dp)


这个题的会有很多情况,表示自己是一个DP弱手,和队友找了很多情况,最后把答案弄出来了。


PS:一直很辛苦地造样例,辛苦了队友haozx


#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define fi first
#define se second
#define INF 0x3f3f3f3f
#define clr(x,y) memset(x,y,sizeof x)
#define PI acos(-1.0)
#define ITER set<int>::iterator
const int Mod = 1e9 + 7;
const int maxn = 2500 + 10;
char a[maxn],b[maxn];
int dp[maxn][maxn];
int main()
{
    int Tcase;scanf("%d",&Tcase);
    while(Tcase --)
    {
        scanf("%s%s",a + 1,b + 1);int lena = strlen(a + 1),lenb = strlen(b + 1);
        bool flag = true;int j = 1;clr(dp,0);dp[0][0] = 1;
        for(int i = 1; i <= lena; i ++)
        {
            for(int j = 1; j <= lenb; j ++)
            {
                if(a[i] == b[j])
                {
                    if( (b[j + 1] == '*' && dp[i][j - 1]) || dp[i - 1][j - 1] == 1)dp[i][j] = 1;
                    if(b[j - 1] == '*' && ( dp[i - 1][j - 3] || dp[i][j - 1]) )dp[i][j] = 1;
                }
                else if(b[j] == '.')
                {
                    if(dp[i - 1][j - 1])dp[i][j] = 1;
                }
                else if(b[j] == '*')
                {
                    if(a[i - 1] == a[i] && (dp[i - 1][j] || dp[i - 1][j - 1]) )dp[i][j] = 1;
                    if(b[j - 1] == '.' && dp[i - 1][j - 1] && a[i] == a[i - 1])dp[i][j] = 1;
                    if(dp[i][j - 2] || dp[i][j - 1] )dp[i][j] = 1;
                }
                else dp[i][j] = 0;
//                if(i == 1)
//                cout << i << " " << j << " " << dp[i][j] << endl;
            }
        }
        if(dp[lena][lenb])
            puts("yes");
        else puts("no");
    }
    return 0;
}


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值