http://oj.chilanggialai.edu.vn/problem/cloj01robot

22/12/2023

http://oj.chilanggialai.edu.vn/problem/cloj01robot

Code
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 100+3;

int n,m;
string f[N][N];

string cong(string a, string b) {
    while(a.size() < b.size()) a = "0" + a;
    while(b.size() < a.size()) b = "0" + b;
    int dig1, dig2, sum, mem=0;
    string ans="";
    for (int i=a.size()-1;i >= 0;i--) {
        dig1 = a[i] - '0';
        dig2 = b[i] - '0';
        sum = mem + dig1 + dig2;
        mem = sum / 10;
        sum = sum%10;
        ans = char(sum+'0') + ans;
    }
    if(mem>0) {
        ans = "1" + ans;
    }
    return ans;
}

signed main() {
    cin >> n >> m;
    for (int i=1;i <= n;i++) {
        f[i][1] = "1";
    }
    for (int i=1;i <= m;i++) {
        f[1][i] = "1";
    }
    for (int i=2;i <= n;i++) {
        for (int j=2;j <= m;j++) {
            f[i][j] = cong(f[i-1][j], f[i][j-1]);
        }
    }
    cout << f[n][m];
    return 0;
}