UVA Solution 111- History grading - Volume 1 in cpp - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Saturday, April 29, 2017

UVA Solution 111- History grading - Volume 1 in cpp

UVA Solution 111- History grading - Volume 1 in cpp


Get UVA online judge Solution 111- History grading - Volume 1 in cpp

UVA Solution 111 :


#include <stdio.h>
#include <string.h>

int main() {
    int n, i, j, flag, order;
    int x[20], y[20];
    scanf("%d", &n);
    for(i = 0; i < n; i++) {
        scanf("%d", &order);
        order--;
        x[order] = i;
    }
    while(1) {
        flag = 0;
        for(i = 0; i < n; i++) {
            if(scanf("%d", &order) != 1)
                {flag = 1;break;}
            order--;
            y[order] = i;
        }
        if(flag)    break;
        int dp[25][25] = {};
        for(i = 1; i <= n; i++) {
            for(j = 1; j <= n; j++) {
                if(x[i-1] == y[j-1])
                    dp[i][j] = dp[i-1][j-1]+1;
                else
                    dp[i][j] = dp[i-1][j] > dp[i][j-1] ?
                        dp[i-1][j] : dp[i][j-1];
            }
        }
        printf("%d\n", dp[n][n]);
    }
    return 0;
}

1 comment:

  1. I didn't understand your solution, can you post a video explaining it? Please.

    ReplyDelete