aboutsummaryrefslogtreecommitdiff
path: root/tests/functional/77_unique_path.sy
blob: 8a1074ace72797142a136e71e3a4be5dc93ab571 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
int uniquePaths(int m, int n) {
    if(m == 1 || n == 1)
        return 1;

    int dp[9];
    int i;
    int j;
    i = 0;
    while(i<m){
        dp[i*3+n-1]=1;
        i = i + 1;
    }
    i = 0;
    while(i<n){
        dp[(m-1)*3+i]=1;
        i = i + 1;
    }
    i=m-2;
    while(i > -1){
        j=n-2;
        while(j > -1){
            dp[i*3+j] = dp[(i+1)*3+j] + dp[i*3+j+1];
            j = j - 1;
        }
        i = i - 1;
    }
    return dp[0];
}
int main(){
    int res;
    int n;
    n=3;
    res = uniquePaths(n, n);
    return res;
}