We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
static int CountRoutes(int N, int M)
{
int[,] dp = new int[N + 1, M + 1];
for (int i = 0; i <= N; i++)
{
for (int j = 0; j <= M; j++)
{
if (i == 0 || j == 0)
{
dp[i, j] = 1;
}
else
{
dp[i, j] = (dp[i - 1, j] + dp[i, j - 1]) % MOD;
}
}
}
return dp[N, M];
}
static void Main()
{
int T = int.Parse(Console.ReadLine());
for (int t = 0; t < T; t++)
{
string[] input = Console.ReadLine().Split();
int N = int.Parse(input[0]);
int M = int.Parse(input[1]);
int result = CountRoutes(N, M);
Console.WriteLine(result);
}
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Project Euler #15: Lattice paths
You are viewing a single comment's thread. Return to all comments →
for C#
using System;
class Program { const int MOD = 1000000007;
}