DP - 字符混编
2015-12-24 10:49
162 查看
字符混编
Problem's Link
----------------------------------------------------------------------------[b]Mean:[/b]
略
[b]analyse:[/b]
略
[b]Time complexity: O(N)[/b]
[b]view code[/b]
#include "bits/stdc++.h"
using namespace std;
class Mixture {
public:
bool chkMixture(string A, int n, string B, int m, string C, int v) {
if (v != n + m)
return false;
bool dp[n + 1][m + 1];
memset(dp,0,sizeof dp);
for (int i = 1; i < n; ++i)
dp[i][0] = (A[i-1] == C[i-1] ? 1 : 0);
for (int i = 1; i < m; ++i)
dp[0][i] = (B[i-1] == C[i-1] ? 1 : 0);
for (int i = 1; i <=n; ++i) {
for (int j = 1; j <= m; ++j) {
dp[i][j] = (A[i-1] == C[i + j - 1] && dp[i - 1][j]) || (B[j-1] == C[i + j - 1] && dp[i][j - 1]);
}
}
cout<<"------------------------------------------------------------"<<endl;
for (int i = 0; i <= n; ++i)
{
for (int j = 0; j <= m; ++j)
{
cout<<dp[i][j]<<" ";
}
cout<<endl;
}
cout<<"------------------------------------------------------------"<<endl;
return dp[n][m];
}
};
int main(int argc, char const *argv[]) {
string s1, s2, s3;
while (cin >> s1 >> s2 >> s3) {
Mixture solution;
if (solution.chkMixture(s1, s1.length(), s2, s2.length(), s3, s3.length()))
cout << "Yes." << endl;
else
cout << "No." << endl;
}
return 0;
}
相关文章推荐
- PHP文件上传问题汇总(文件大小检测、大文件上传处理)
- JS 字符串操作函数 往指定位置插入字符 删除指定位置字符 替换指定位置字符
- 3D打印如何助力中国制造破局
- 笔试面试题总结(三)--- 软件开发
- MySQL连接问题浅析
- MySQL连接问题浅析
- MySQL连接问题浅析
- Linux 安装python插件 测网速
- cURL进行HTTPS连接POST数据
- 数据库面试题 Java 程序员 SQL 深入解析(一)
- linux 下 openOffice swftools 的安装
- MySQL连接问题浅析
- .Net 项目代码风格要求小结
- powerdesigner 画ER图
- linux挂载CDROM
- Canonical:全球 Ubuntu 用户可能超过了10亿
- 让你分分钟学会javascript闭包
- 项目使用log4j,指定日志打印出来的格式,打印到指定文件夹,每天打印一个日志等配置
- 排序算法:快速排序
- iOS开发61- CocoaPods安装和使用