Answer to Question #223737 in Java | JSP | JSF for Khushbu

Question #223737
Charles and the Necklace
Charles wants to buy a necklace in which.
1. There is a minimum of 1 pearl and maximum of X pearls, such that each
pearl has its own magnificent coefficient
2. The pearls should be in non-decreasing order of their magnificence power.
You are given the maximum number of pearls in a necklace and the range of
the magnificent coefficients of the pearls. Find the number of necklaces that
can be made that follow the mentioned conditions.​
1
Expert's answer
2021-08-06T04:25:17-0400
import java.util.Scanner;
public class Main
{
    static int c;


    public static void main(String[] args)
    {
        c = 0;
        System.out.print("Enter N : ");
        int n = (new Scanner(System.in)).nextInt();
        for (int i = 0; i < n; i++)
            print(1, n, i, "");
        System.out.println("The count is : " + c);


    }
    private static void print(int s, int n, int x, String p)
    {
        if (x == 0)
            for (int i = s; i <= n; i++) {
                System.out.println(p + i);
                c++;
            }
        else
            for (int i = s; i <= n - x; i++)
                print(i + 1, n, x - 1, p + i + " ");
    }


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS