hdu-6170 Two strings
来源:互联网 发布:淘宝女人秋装 编辑:程序博客网 时间:2024/06/06 09:41
题意:给两个字符串,第一个字符串只包括大写字母和小写字母,第二个字符串包括大小写字母和 ' . ',' * '。.字符可以替换成任何字符,* 字符可以换成第二个字符串*之前的那个字符,问:第二字符串能否通过一系列变换得到第一个字符串。
思路:令dp[i][j]代表b串中[1~i]和a串中[1~j]的字符是否匹配,匹配为1,不匹配为0,有以下状态转移关系:
1. 当
2. 当
#include <cstdio>#include <iostream>#include <string.h>#include <string>#include <map>#include <queue>#include <vector>#include <set>#include <algorithm>#include <math.h>#include <cmath>#include <stack>#define mem0(a) memset(a,0,sizeof(a))#define meminf(a) memset(a,0x3f,sizeof(a))#define LL long long#define siz 2505using namespace std;char S[siz];char T[siz];int dp[siz][siz];void solve(){ int slen = strlen(S); int tlen = strlen(T); bool flag = true; //cout<<slen<<" "<<tlen<<endl; for(int i=0; i<siz; i++) { for(int j=0; j<siz; j++) { dp[i][j] = 0; } } dp[0][0] = 1; for(int i=1; i<=tlen; i++) { if(T[i] == '*' &&i == 2) dp[i][0] = 1; for(int j=1; j<=slen; j++) { //if(i == 0 && j == 0) continue; if(T[i] == '.'){ dp[i][j] = dp[i-1][j-1]; // cout<<i<<" "<<j<<" --"<<dp[i][j]<<endl; } else if(T[i] != '*'){ if(T[i] == S[j]) dp[i][j] = dp[i-1][j-1]; //cout<<i<<" --"<<j<<" "<<dp[i][j]<<" "<<T[i]<<" "<<S[j]<<" "<<dp[i-1][j-1]<<endl; } else{ dp[i][j] = max(dp[i-2][j],dp[i-1][j]); if(dp[i][j-1]&&S[j] == S[i - 1]) dp[i][j] = 1; //cout<<i<<"--"<<j<<"--"<<dp[i][j]<<endl; } } } if(dp[tlen][slen] == 1) { cout<<"yes"<<endl; } else puts("no");}int main(){ int t; scanf("%d\n",&t); while(t--) { scanf("%s",S+1); scanf("%s",T+1); S[0] = '#'; T[0] = '#'; solve(); } 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)
- python中的list和tuple
- C++笔记_03面向对象3
- 《.NET 设计规范》第 8 章:使用规范
- JVM内存模型之方法区
- python操作数据库
- hdu-6170 Two strings
- 加载配置文件的四种方式
- “NODE_ENV” is not recognized as an internal or external command
- Linux下的图片编辑软件和画图软件
- c/c++整理析构函数
- C++笔记_03面向对象4
- Python3爬虫下载pdf(一)
- POJ 1986 RMQ+LCA
- 1.数码相框之框架