Advertisement
Guest User

RecursiveNK

a guest
Feb 14th, 2021
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.61 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace RecursiveNK
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             int n = int.Parse(Console.ReadLine());
  12.             int k = int.Parse(Console.ReadLine());
  13.             Console.WriteLine(String.Join(" ", Solve(n, k)));
  14.         }
  15.  
  16.         public static List<int> Solve(int n, int k)
  17.         {
  18.             return n == 1 ? new List<int>() { 1 } : Solve(n - 1, k).Concat(new List<int>() { Solve(n - 1, k).Skip(Math.Max(0, Solve(n - 1, k).Count() - k)).Sum() }).ToList();
  19.         }
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement