Algorithm 用固定值填充n个位置的方法
有多少种方法可以用2个固定值填充n个位置,用2个选定值之间的值填充其余位置,这样就不会得到重复的位置 示例:n=4,固定值1和3Algorithm 用固定值填充n个位置的方法,algorithm,combinations,permutation,Algorithm,Combinations,Permutation,有多少种方法可以用2个固定值填充n个位置,用2个选定值之间的值填充其余位置,这样就不会得到重复的位置 示例: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
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)-重复项
,但不能减去重复项 我不确定是否理解,但如果我理解得很好,您有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是你所说的最大最小值+1时
例如,他们有54种不同的填写方式,请澄清您考虑的案例数量以及如何定义?也许你必须考虑所有2个固定值在2个位置的所有可能的定位……或者使用的案例数量和位置作为单独的数据给出?