当前位置: 代码迷 >> C# >> 有n个位置,每个位置可取3个值,问有多少可能性?解决思路
  详细解决方案

有n个位置,每个位置可取3个值,问有多少可能性?解决思路

热度:113   发布时间:2016-05-05 04:59:45.0
有n个位置,每个位置可取3个值,问有多少可能性?
设n=4,则有
0 0 0 0
0 0 0 1
0 0 0 2
0 0 1 0
.....

问:
1、这叫做什么问题?全排列问题?全组合问题?背包问题?丢番图问题?薛定谔的猫问题?还是什么问题?

2、给出算法,列出所有可能性。

------解决思路----------------------
4位3进制问题~_~
------解决思路----------------------
C(n,3) = pn/(p3*p(n-3))
------解决思路----------------------
不知这个是否符合你的要求
namespace 控制台训练
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = 0;
            for(int iOne=0;iOne<4;iOne++)
            {
                
                for(int iTwo=0;iTwo <4;iTwo ++)
                {
                    for(int iThree=0;iThree <4;iThree ++)
                    {
                        for(int iFour=0;iFour <4;iFour ++)
                        {
                            Console .Write ("{0}\t{1}\t{2}\t{3}\n",iOne,iTwo ,iThree ,iFour );
                            count++;
                        }
                    }
                }
            }
            Console.WriteLine("count={0}", count);
            Console.ReadKey();
        }
    }
}
------解决思路----------------------
重复排列问题。

参见http://eprob.math.nsysu.edu.tw/PerComb/repPerm/index.html
  相关解决方案