Advertisement
svetlai

Staircases

Nov 20th, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. namespace Stairs
  2. {
  3.     using System;
  4.  
  5.     public class Program
  6.     {
  7.         private static long[,] count;
  8.  
  9.         public static void Main()
  10.         {
  11.             int n = int.Parse(Console.ReadLine());
  12.  
  13.             count = new long[n + 1, n + 1];
  14.  
  15.             count[0, 0] = 1;
  16.             count[1, 1] = 1;
  17.             count[2, 2] = 1;
  18.  
  19.             for (int i = 3; i <= n; i++)
  20.             {
  21.                 for (int j = 0; j <= i; j++)
  22.                 {
  23.                     for (int k = 0; k < j && i - j >= k; k++)
  24.                     {
  25.                         count[i, j] += count[i - j, k];
  26.                     }
  27.                 }
  28.             }
  29.  
  30.             long answer = 0;
  31.             for (int i = 1; i < n; i++)
  32.             {
  33.                 answer += count[n, i];
  34.             }
  35.  
  36.             Console.WriteLine(answer);
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement