Cod sursa(job #2427902)

Utilizator cristicretancristi cretan cristicretan Data 2 iunie 2019 18:33:07
Problema Subsir Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.25 kb
/*
* @Author: Cristi Cretan
* @Date:   02-06-2019 18:09:36
* @Last Modified by:   Cristi Cretan
* @Last Modified time: 02-06-2019 18:33:00
*/
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
// #define f cin
// #define g cout
#define dbg(x) cerr<<#x<<" = "<<x<<endl;
#define dbg_v(v,n) {cerr<<#v<<" = [";for(int III=1;III<=n;III++)cerr<<v[III]<<(III!=n?",":"]\n");}
#define ll long long
#define ld long double
#define pii pair<int,int>
#define MOD 1000000007
#define zeros(x) x&(x-1)^x
#define NMax 1027
using namespace std;

ifstream f("subsir.in");
ofstream g("subsir.out");

int main()
{
    int dp[NMax][NMax];
    char s1[NMax], s2[NMax];
    f.getline(s1, NMax);
    f.getline(s2, NMax);

    int A = strlen(s1);
    int B = strlen(s2);

    for (int i = 0; i < A; ++i)
        for (int j = 0; j < B; ++j)
            if (s1[i] == s2[j])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else
                dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);

    // for (int i = 0; i < A; ++i) {
    //     for (int j = 0; j < B; ++j)
    //         printf("%d ", dp[i][j]);
    //     printf("\n");
    // }
    int k = 0;
    for (int i = 0; i < B; ++i)
        if (dp[A - 1][i] == dp[A - 1][B - 1]) k++;
    printf("%d\n", k/dp[A - 1][B - 1] + 1);
    return 0;
}