HDU 6170 Two strings
来源:互联网 发布:纹理过滤 三线性优化 编辑:程序博客网 时间:2024/05/19 02:43
题目地址
题意:告诉你两个字符串,第二串有两种特殊字符(第一种是’.‘可以代表任意字符,第二种是’*‘可以复制任意次前一个字符,或者为空字符,或者删除前一个字符),求两个字符串能不能匹配。
思路:通过dp的想法,dp[i][j]代表的是第一个字符串的到第i个字符,与第二个字符串到第j个字符能不能匹配,能匹配就赋那个字符。着重讲一下为什么第一个字符串是从0开始但是第二个字符串是从1
开始的,因为会有在第一个和第二个的情况,所以这样的话,按照’‘的规则就可以删除,所以要把这种情况考虑进去。
#include <iostream>#include <cstring>#include <string>#include <queue>#include <vector>#include <map>#include <set>#include <stack>#include <cmath>#include <cstdio>#include <algorithm>#include <iomanip>#define N 3010#define LL __int64#define inf 0x3f3f3f3f#define lson l,mid,ans<<1#define rson mid+1,r,ans<<1|1#define getMid (l+r)>>1#define movel ans<<1#define mover ans<<1|1using namespace std;const LL mod = 1000000007;char dp[N][N];int main() { cin.sync_with_stdio(false); int T; int lena, lenb; string a, b; cin >> T; while (T--) { cin >> a >> b; memset(dp, -1, sizeof(dp)); lena = a.length(); lenb = b.length(); dp[0][0] = 0; for (int i = 0; i <= lena; i++) { for (int j = 1; j <= lenb; j++) { if (i != 0 && a[i - 1] == b[j - 1] && dp[i - 1][j - 1] != -1) {//相等的时候,当等于-1的时候就说明之前是已经失配的 dp[i][j] = a[i - 1]; } else if (i != 0 && b[j - 1] == '.'&&dp[i - 1][j - 1] != -1) { dp[i][j] = a[i - 1]; } else if (b[j - 1] == '*') { if (dp[i - 1][j - 1] == a[i - 1] || dp[i - 1][j] == a[i - 1]) {//当前位新增一位或者重复 dp[i][j] = a[i - 1]; } if ((dp[i][j - 2] != -1 && j != 1) || dp[i][j - 1] != -1) { dp[i][j] = 0; } } } } if (dp[lena][lenb] == -1) { cout << "no" << endl; } else { cout << "yes" << endl; } } return 0;}
阅读全文
0 0
- hdu 6170 Two strings
- HDU 6170:Two strings
- HDU 6170 Two strings
- hdu 6170 Two strings
- HDU-6170 Two strings
- hdu 6170 Two strings
- HDU 6170 Two strings
- hdu-6170 Two strings
- hdu 6170 Two strings dp
- hdu 6170 Two strings(DP)
- HDU 6170(Two strings-DP)
- hdu 6170 Two strings(dp)
- hdu 6170 Two strings dp模拟
- Hdu 6170 Two strings【思维+Dp】
- HDU 6170 Two strings (dp)
- HDU 6170 Two strings (二维DP)
- hdu 6170 Two strings(线性dp)
- HDU 6170 Two strings(dp)
- 两粒种子,一片森林 jzoj 2017.8.22 B组
- HDMI之DDC通道
- 添加的依赖
- 多线程
- python: IO操作
- HDU 6170 Two strings
- 异步协程处理requests阻塞
- java提高篇(八)-----详解内部类
- lightoj 1011 Marriage Ceremonies (KM模板题)
- ReactNative-综合案例(01)
- 这个“打工二代”凭啥成了高层次人才
- HDU6165 FFF at Valentine【BFS】
- UVA
- MOB短信验证