CSharp · Console
using System;
using System.Numerics;
public class Program
{
public static BigInteger GetCountOfWays(int n)
{
const int MaxValue = 1001;
if (n >= MaxValue)
{
throw new Exception(string.Format("N should be less than {0}", MaxValue));
}
BigInteger[] result = new BigInteger[n+1];
result[0] = 0;
result[1] = 1;
result[2] = 2;
for (int i = 3; i <= n; i++)
{
result[i] = result[i - 1] + result[i - 2] + 1;
}
return result[n];
}
public static void Main()
{
Console.WriteLine("UniLecs");
Console.WriteLine(string.Format("Answer = {0}", GetCountOfWays(3))); // 4
Console.WriteLine(string.Format("Answer = {0}", GetCountOfWays(4))); // 7
Console.WriteLine(string.Format("Answer = {0}", GetCountOfWays(5))); // 12
Console.WriteLine(string.Format("Answer = {0}", GetCountOfWays(10))); // 143
}
}