GetCount.cs

CSharp · Console

/Program.cs

using System;
					
public class Program
{
	private static int Max = 51;
	private static long[] f = new long[Max];
	
	public static long GetCount(int N)
	{
		if (N > Max)
		{
			throw new Exception(string.Format("N should be less then {0}", Max));
		}
		
		f[1] = 2; f[2] = 4; f[3] = 7;
		
		for (int i = 4; i <= N; i++)
		{
			f[i] = f[i - 1] + f[i - 2] + f[i - 3];
		}
		
		return f[N];
	}	
	
	public static void Main()
	{
		Console.WriteLine("UniLecs");
		Console.WriteLine(string.Format("Answer = {0}", GetCount(4))); // 13
	}
}
;