15 AnswersNew Answer
Answer for the above question #java https://code.sololearn.com/cS4oDAW4BUpJ/?ref=app
I think he wants to print some substrings or subsequence from a word //after an example it will be understood clearly
what u mean by combn. of r String from n String ? //provide an example
(and a language)
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.
@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 !
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
He seems to be talking about permutation and combinations or only he knows :)
Please provide 2 examples, it is not clear what to do.
Me neither, the maths are complex and the implementation is close to being trivial. I will learn about this when I need it.
@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.
This doesn't explain it well to me again.
@swim your explanation is correct anyone can tell the combination but the main problem is to display those all different possible selection of products
That's also easy. Hint: use a set if you may use every product just once.
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