Skip to content

Instantly share code, notes, and snippets.

@tomfuru
Created August 6, 2012 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomfuru/3272418 to your computer and use it in GitHub Desktop.
Save tomfuru/3272418 to your computer and use it in GitHub Desktop.
dailycoding-20120806
using System;
namespace DailyCoding
{
class MainClass
{
/*
* 2 × 2 のマス目の左上からスタートした場合、引き返しなしで右下にいくルートは 6 つある。
* では、20 × 20 のマス目ではいくつのルートがあるか。
*/
public static void Main(string[] args)
{
Console.WriteLine(GetRouteNum(20));
}
private static long GetRouteNum(long size)
{
return Combination(size * 2, size);
}
private static long Combination(long left, long right)
{
long res = 1;
for (long i = 1; i <= right; i++) {
res *= left - right + i;
res /= i;
}
return res;
}
}
}
// 137846528820
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment