Skip to content

Instantly share code, notes, and snippets.

@cbdavide
Created November 4, 2018 19:19
Show Gist options
  • Save cbdavide/634651c250dec87693690f8cee8a7ae8 to your computer and use it in GitHub Desktop.
Save cbdavide/634651c250dec87693690f8cee8a7ae8 to your computer and use it in GitHub Desktop.
UVa 10192
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define endl '\n'
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
string a, b;
int dp[107][107];
int f(int i, int j) {
if(i == a.size() || j == b.size())
return 0;
if(~dp[i][j]) return dp[i][j];
if(a[i] == b[j])
dp[i][j] = f( i + 1, j + 1 ) + 1;
else
dp[i][j] = max(f( i+1, j ), f( i, j+1 ));
return dp[i][j];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int z = 1;
while(getline(cin, a), a[0] != '#') {
getline(cin, b);
memset(dp, -1, sizeof dp);
cout << "Case #" << z++ << ": you can visit at most "
<< f( 0, 0 ) << " cities." << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment