2013-10-07 22 views
2

我们可以用2个固定值填充n个地方以及2个选定地点之间的值的休息地方的方法数量是多少,这样我们就不会有重复?用固定值填充n个地方的方法

例如:n = 4时,固定值1和3

case 1 : fix 1 on position 1 and 3 on position 2 

1 3 1 1 
1 3 1 2 
1 3 2 1 
1 3 2 2 
1 3 1 3 
1 3 3 1 
1 3 3 3 
1 3 2 3 
1 3 3 2 

case 2 : fix 1 on position 1 and 3 on position 3 

1 1 3 1 
1 1 3 2 
1 2 3 1 
1 2 3 2 
1 3 3 2 
1 2 3 3 
1 3 3 1 
1 1 3 3 
1 3 3 3 
now in case 1 and 2 : 1 3 3 3 and 1 3 3 1 and 1 3 3 2 are repeating 

case 3 : ....similarly other cases follow 

我所做至今是:nC2 * POWER((max-min+1) , n-2) - duplicates但不能减去重复。

+0

请说明您有多少个案件正在考虑,以及它们是如何定义的?也许你必须考虑2个固定值在任何2个位置的所有可能的定位? ..或者使用的案例和职位的数量是作为单独的数据给出的? –

回答

0

我不确定要理解,但是如果我理解的很好,您有n(数字的位数)和一系列适用的数字。 x是此范围内的数字的数量。

您必须将此视为计算基数x。

例:

x = 3 (we really don't care about min and max it change nothing) 
n = 4 

1 1 1 1 
1 1 1 2 
1 1 1 3 
1 1 2 1 
1 1 2 2 


etc. 

使灌装的数量应该是:

POWER(x, n)-POWER(x, n-1) 

当x是你所谓的MAX-MIN + 1

对于示例他们是54个不同填写方法