Thursday, 7 January 2016

UVa 10192 - Vacation

//\\__ hr1212 __//\\

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;

#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1000100
#define MOD 1000000007

int n,m,dp[500][500];

int main(){
    int r,k,i,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0;
    ll ans=0;string p,q;
    t=1;
    while(getline(cin,p)){
        if(p[0]=='#')
            break;
        getline(cin,q);
        n=p.size()+1;m=q.size()+1;
        clr(dp,0);
        f(i,1,n){
            f(j,1,m){
                if(p[i-1]==q[j-1])
                    dp[i][j]=dp[i-1][j-1]+1;
                else
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
        z=dp[n-1][m-1];
        printf("Case #%d: you can visit at most %d cities.\n",t++,z);
    }

    return 0;
}

No comments:

Post a Comment