概述
字符混编
Problem's Link
----------------------------------------------------------------------------
Mean:
略
analyse:
略
Time complexity: O(N)
view code
#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;
}
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;
}
最后
以上就是自然汽车为你收集整理的DP - 字符混编字符混编 Problem's Link 的全部内容,希望文章能够帮你解决DP - 字符混编字符混编 Problem's Link 所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复