fork download
#include <bits/stdc++.h>
#define ll long long
#define PI 3.14159265359
#define DP(x, y) memset(x, y, sizeof x)
#define all(x) x.begin(), x.end()
#define read(x) freopen("x", "r", stdin);
#define write(x) freopen("x", "w", stdout);

using namespace std;

ll gcd(ll a,ll b) { while(b) { ll x = a; a = b; b = x % b; } return a; }
ll lcm(ll a,ll b) { return a / gcd(a, b) * b; }
ll nC2(ll n) { return (n)*(n-1)/2; }
ll summing(ll n) { return (n)*(n+1); }

int Paths(int i, int j, int n, int m, vector<vector<char>>&grid, vector<vector<bool>>&vis, vector<vector<int>>&dp) {

    if (i == n && j == m) {
        return 1;
    }
    if (i > n || j > m || i == 0 || j == 0) {
        return 0;
    }
    if ( grid[i][j] == '*' || vis[i][j] ) {
        return 0;
    }
    if (~dp[i][j]) {
        return dp[i][j];
    }

    vis[i][j] = 1;
    int x = Paths(i+1, j, n, m, grid, vis, dp);
    int y = Paths(i, j+1, n, m, grid, vis, dp);
    vis[i][j] = 0;

    return (dp[i][j] = x+y);

}

void solve() {

    int n,m; cin >> n >> m;

    vector<pair<int,int>> breaking;
    vector<vector<char>> grid(n+1, vector<char>(m+1, '.'));
    vector<vector<bool>> vis(n+1, vector<bool>(m+1, 0));

    vector<vector<int>> dp(n+1, vector<int>(m+1, -1));

    cin.ignore();

    for (int i=0; i<n; i++) {

        string s, row, col;
        getline(cin, s);

        stringstream ss(s);

        ss >> row;

        while (ss >> col) {
            breaking.push_back({stoi(row), stoi(col)});
        }
    }

    for (auto i:breaking) {
        grid[i.first][i.second] = '*';
    }

    cout << Paths(1,1,n,m,grid,vis,dp) << "\n\n";

}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    ll t=1; cin >> t;
    while (t--) { solve(); }

    return 0;
}
Success #stdin #stdout 0.01s 5300KB
stdin
Standard input is empty
stdout
0