Answer to Question #282478 in C for Nnn

Question #282478

How to Attempt?





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-12-24T11:46:01-0500


#include <bits/stdc++.h>
using namespace std;
int
main ()
{
  int sol (int n, int lm, int hm)
  {


    vector < vector < int >>dp (n, vector < int >(hm - lm + 1, 1));
    int ans = hm - lm + 1 + n - 1;


    for (int i = 1; i < dp[0].size (); i++)
      {
	dp[0][i] += dp[0][i - 1];
      }


    for (int i = 1; i < n; i++)
      {
	for (int j = 1; j < dp[0].size (); j++)
	  {
	    ans += dp[i - 1][j];
	    dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
	  }
      }


    return ans;
  }
}

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