Determine whether a symbol is part of the ith combination nCr

前端 未结 3 1836
感情败类
感情败类 2021-01-21 03:15

UPDATE: Combinatorics and unranking was eventually what I needed. The links below helped alot:

http://msdn.microsoft.com/en-us/library/aa289166(v=vs.71).aspx

ht

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-21 04:03

    I have written a class to handle common functions for working with the binomial coefficient, which is the type of problem that your problem falls under. It performs the following tasks:

    1. Outputs all the K-indexes in a nice format for any N choose K to a file. The K-indexes can be substituted with more descriptive strings or letters. This method makes solving this type of problem quite trivial.

    2. Converts the K-indexes to the proper index of an entry in the sorted binomial coefficient table. This technique is much faster than older published techniques that rely on iteration. It does this by using a mathematical property inherent in Pascal's Triangle. My paper talks about this. I believe I am the first to discover and publish this technique, but I could be wrong.

    3. Converts the index in a sorted binomial coefficient table to the corresponding K-indexes.

    4. Uses Mark Dominus method to calculate the binomial coefficient, which is much less likely to overflow and works with larger numbers.

    5. The class is written in .NET C# and provides a way to manage the objects related to the problem (if any) by using a generic list. The constructor of this class takes a bool value called InitTable that when true will create a generic list to hold the objects to be managed. If this value is false, then it will not create the table. The table does not need to be created in order to perform the 4 above methods. Accessor methods are provided to access the table.

    6. There is an associated test class which shows how to use the class and its methods. It has been extensively tested with 2 cases and there are no known bugs.

    To read about this class and download the code, see Tablizing The Binomial Coeffieicent.

    This class can easily be applied to your problem. If you have the rank (or index) to the binomial coefficient table, then simply call the class method that returns the K-indexes in an array. Then, loop through that returned array to see if any of the K-index values match the value you have. Pretty straight forward...

提交回复
热议问题