From d19837b878b4c81fe78144b7fd742ba3eca2cb29 Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Mon, 7 Oct 2024 17:20:39 +0800 Subject: [PATCH] update --- src/wildcard_match/wildcard_match.cpp | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/wildcard_match/wildcard_match.cpp diff --git a/src/wildcard_match/wildcard_match.cpp b/src/wildcard_match/wildcard_match.cpp new file mode 100644 index 0000000..a19012a --- /dev/null +++ b/src/wildcard_match/wildcard_match.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +static const size_t MAX_LEN {(size_t)2e3+5}; +static std::string s,p; +static constexpr auto range {std::ranges::views::iota}; + +static std::bitset dp[MAX_LEN]; + +int main(){ + std::cin>>s>>p; + + dp[0][0] = true; + + for(const size_t i:range((size_t)1,s.size()+1)){ + for(const size_t j:range((size_t)1,p.size()+1)){ + const auto get_p = [](const size_t n)->char{return p[n-1];}; + const auto get_s = [](const size_t n)->char{return s[n-1];}; + + if(get_p(j) == get_s(j) || get_p(j)=='?'){ + dp[i][j] = dp[i-1][j-1]; + }else if(get_p(j)=='*'){ + dp[i][j] = dp[i-1][j] || dp[i][j-1]; //01背包,查看是否使用这个字符 + } + } + } + + std::cout<<(dp[s.size()][p.size()]==true?"yes":"no")<<'\n'; +} \ No newline at end of file