Advertisement
Dennnhhhickk

C

Nov 13th, 2017
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. // ConsoleApplication3.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <math.h>
  7. #include <iomanip>
  8. #include <algorithm>
  9. #include <fstream>
  10. #include <string>
  11. #include <map>
  12.  
  13. using namespace std;
  14.  
  15. typedef long long ll;
  16. typedef unsigned long long ull;
  17. typedef long double ld;
  18. typedef string str;
  19.  
  20. const ll S = 10010;
  21. const ll T = 1010;
  22. const ll INF = 1e12;
  23.  
  24. str s, t;
  25. ll dp[S][T], nx[S];
  26. map <char, int> mp;
  27.  
  28. ifstream in;
  29. ofstream out;
  30.  
  31. int main()
  32. {
  33.     in.open("input.txt");
  34.     out.open("output.txt");
  35.     in >> s >> t;
  36.     for (int i = 0; i < s.size(); i++)
  37.         for (int j = 0; j < t.size(); j++)
  38.             dp[i][j] = INF;
  39.     if (s[0] == t[0])
  40.         dp[0][0] = 1;
  41.     for (int i = 1; i < s.size(); i++)
  42.         for (int j = 0; j < t.size(); j++)
  43.             if (j != 0)
  44.                 dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j] + (s[i] == t[j] ? 1 : 0));
  45.             else
  46.                 dp[i][j] = dp[i - 1][j] + (s[i] == t[j] ? 1 : 0);
  47.     for (int i = 0; i < s.size(); i++, out << endl)
  48.         for (int j = 0; j < t.size(); j++)
  49.             out << dp[i][j] << ' ';
  50.     ll mn = 0;
  51.     for (int i = 0; i < t.size(); i++)
  52.         if (dp[s.size() - 1][i] < dp[s.size() - 1][mn])
  53.             mn = i;
  54.     cout << mn << endl;
  55.     system("pause");
  56.     return 0;
  57. }
  58.  
  59. /*
  60. abacaba
  61. aba
  62. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement