CSharp · Console
using System;
public class Program
{
static long CountOfHandshake(int N)
{
int K = N / 2; // кол-во пар, ктр жмут друг другу руки
long[] result = new long[K + 1];
result[0] = result[1] = 1;
for (int i = 2; i < result.Length; i++)
{
for (int j = 0; j < i; j++)
{
result[i] += result[j] * result[i - j - 1];
}
}
return result[K];
}
public static void Main()
{
Console.WriteLine("UniLecs");
Console.WriteLine(string.Format("Answer = {0}", CountOfHandshake(2))); // 1
Console.WriteLine(string.Format("Answer = {0}", CountOfHandshake(4))); // 2
Console.WriteLine(string.Format("Answer = {0}", CountOfHandshake(6))); // 5
Console.WriteLine(string.Format("Answer = {0}", CountOfHandshake(8))); // 14
Console.WriteLine(string.Format("Answer = {0}", CountOfHandshake(10))); // 42
}
}