Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Reflection.Emit;
- namespace ConsoleApplication1945
- {
- internal class Program
- {
- public static void Main()
- {
- Console.WriteLine(CountWays(11));
- }
- // Каждое число вычисляется на основе вычисленных ранее, а не каждый раз решается с нуля
- public static int CountWays(int n)
- {
- if (n < 0) throw new ArgumentException();
- if (n <= 2) return 1;
- var date = new int[4];
- for (var i = 0; i <= 2; i++) date[i] = 1;
- for (var i = 3; i <= n; i++)
- {
- date[3] = date[0] + date[1];
- date[0] = date[1];
- date[1] = date[2];
- date[2] = date[3];
- }
- return date[3];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement