您当前的位置: 首页 >  动态规划

对方正在debug

暂无认证

  • 3浏览

    0关注

    399博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

正则表达式匹配(动态规划)

对方正在debug 发布时间:2020-02-14 15:22:16 ,浏览量:3

题目:https://leetcode-cn.com/problems/regular-expression-matching/

#include
using namespace std;

class Solution {
public:
    bool isMatch(string s, string p) {
    	/*
    	*动态规划 
    	*dp[i][j]表示s的前i个字符是否与p的前j个字符匹配 
    	*初始dp[][]为-1,dp[0][0] = 1 
    	*当s[i] == p[j] || p[j] == '.'时 dp[i][j] = dp[i-1][j-1]
    	*当p[j] == '*'时
		*1)如果p[j-1]不能和s[i]匹配,那么只能放弃p[j-1]字符 dp[i][j] = dp[i][j-2] 
    	*2)如果p[j-1]能和s[i]匹配,那么'*'有3种选择:匹配0、1、多个 
    	*3)注意空串和p串的dp初始化 如空串""和串"a*"是可以匹配的 
    	*/
        int n = s.length(),m = p.length();
        vector dp(n+2);
        for(int i = 0;i             
关注
打赏
1664895754
查看更多评论
0.0382s