recursive

A collection of 12 post

Factorial

Problem Enter a natural number N to get the value of N!. N! = n(n-1)(n-2)…2*1. If N=5 then 5!=54321=120. input In the first line, the natural number N (3<=n<=10) is entered. output Print the N factorial value on the first line. Solution plus subtract

Number of Combinations (Memoization)

Problem The equation above is solution for number of combinations. But instead of using this formula, write a program that uses the following equation to find the combinatorial number using recursion. input The first line contains the natural numbers n (3<=n<=33) and r (0<=r<=n). output Prints the…

Finding Permutations

Problem If N natural numbers less than or equal to 10 are given, M out of them are selected and all methods are printed out. input The first line is given the natural numbers N(3<=N<=10) and M(2<=M<=N) In the second line, N natural numbers are given in ascending order output Prints the result on the…

Coin Exchange

Problem How can I exchange change for the smallest number of coins when several units of coins are given as follows? Each unit of coins can be used indefinitely. input In the first line, the number of types of coins N (1<=N<=12) is given. The second line is given N types of coins, and the next line…

Find Duplicate Permutations

Problem There are marbles numbered from 1 to N. Of these, duplicates are allowed, and all methods of selecting M times and arranging them are printed out. input The first line is given the natural numbers N(3<=N<=10) and M(2<=M<=N). output Prints the result on the first line. Prints the last total…

Finding the Maximum Score (DFS)

Problem In order to get good grades in this information olympiad, Hyun-soo is going to solve the N problems given by the teacher. Each question is given a score for solving it and the time it takes to solve it. We need to get the maximum score out of N problems within the time limit M. (The problem…

Dog Riding

Problem Cheol-su wants to go to the market with his dog. But his truck cannot carry more than C kilograms. Cheol-su wants to burn his dog the most without going over C. Given N dogs and the weight W of each dog, write a program to find the heaviest weight that Cheolsu can carry in a truck. input The…

Subsets with Equal Sum (DFS)

Problem Given a set of natural numbers with N elements, When this set is divided into two subsets, if there is a case where the sum of the elements of the two subsets is equal, “YES” is output, Otherwise, write a program that prints “NO”. The two subsets divisible by two are disjoint sets, and the…

Subset (DFS)

Problem Given a natural number N, write a program that prints all subsets of a set with elements 1 through N. input The first line is given a natural number N (1<=N<=10). output From the first line, the subsets are printed in the same order as in the output example below, one for each line However…

Binary Tree Traversal (Depth First Search)

Problem Practice forward and backward traversal of the binary tree as shown in the figure below. output Pre-traversal output: Inter-traversal output: Post-traversal output: Solution Pre traversal Inter traversal Post traversal

Recursive Binary

Problem Write a program that converts decimal number N into binary number and outputs it. However, it must be output using a recursive function. input The first line is given a decimal number N (1<=N<=1,000). output Print the binary number on the first line. Solution

Recursive Function

Problem Write a program that outputs 1 to N using a recursive function when a natural number N is input. input In the first line, an integer N (3<=N<=10) is entered. output print on the first line Solution