zoukankan      html  css  js  c++  java
  • DP

    字符混编 

    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;
    }
     
     
  • 相关阅读:
    File类总结
    MyBatis框架一级缓存与二级缓存
    SpringMVC运行原理总结
    SpringMVC:详述拦截器
    SpringMVC:自定义视图及其执行过程
    详述ThreadLocal
    浅析MVC中的数据流动
    error: gpg failed to sign the data 的一个解决办法
    保险业务核心系统设计参考
    奇怪的404
  • 原文地址:https://www.cnblogs.com/crazyacking/p/5072380.html
Copyright © 2011-2022 走看看