 Combination of "r" strings from "n" strings | Sololearn: Learn to code for FREE!

+3

# Combination of "r" strings from "n" strings

I want anyone to answer a code for this question!!

0

Answer for the above question #java https://code.sololearn.com/cS4oDAW4BUpJ/?ref=app

+16

I think he wants to print some substrings or subsequence from a word //after an example it will be understood clearly

+14

what u mean by combn. of r String from n String ? //provide an example

+11

+5

i think what he want to say is that we have a string of n characters and we can take only r from that n characters and show various combinations of these r characters.

+5

@Manjunath, General explanation If the order in which you select the product matters i.e. if  you must select product A before product B and repetition is allowed i.e you can choose a product more than once then the total number of ways you can select the products is given by the formula N^R (N raise to the power R) where N = total number of products and R = number of products to choose. So here it becomes 10^5 = 100000 ways If repetition is not allowed then number if ways is given by  N !/(N - R) !. N and R have same meaning as mentioned earlier and N ! (N Factorial). It is calculated as say N = 5, so 5! = 5x4x3x2x1 This whole thing is called Permutation. If the order of selecting the products doesn't matter and repetition is not allowed (can't choose a product more than once). Then the total number of ways the products can be selected is given by the fornula N ! / (R! * (N - R) ! N and R have same meaning as mentioned earlier. If the order doesn't matter and repetition is allowed then the total number of ways the products can be selected is given by the Formula (N + R - 1) ! / (R ! * (N - 1) ! ). N and R have same meaning as mentioned earlier. This whole thing is called Combination. I hope you can write the program yourself or use a calculator.  I am not writing a program for this !

+3

combine means selection different ways "r" names from" n" names and I want a code from c or c++ from this piece of code we can achieve more things

+3

He seems to be talking about permutation and combinations or only he knows :)

+2

Please provide 2 examples, it is not clear what to do.

+2

Me neither, the maths are complex and the implementation is close to being trivial. I will learn about this when I need it.

+2

@Manjunath, You can do one thing, take a string of 10 characters where each character represents a product then generate and display all permutations of the string. You can write your own program or search sololearn or the net for the implementation. Max ways will be 10 ! if each character is different or less than (total unique ways) 10! if character repeats. You can then select X no of ways from the total. Where X is the number you get using the formula mentioned in my earlier post.

+1

This doesn't explain it well to me again.

+1

@swim your explanation is correct anyone can tell the combination but the main problem is to display those all different possible selection of products

+1

That's also easy. Hint: use a set if you may use every product just once.

0

ex:- we have 10 products in which we have to select 5 products. output: the number of different ways of selection of those 5 products