Created
August 6, 2012 09:03
-
-
Save tomfuru/3272418 to your computer and use it in GitHub Desktop.
dailycoding-20120806
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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