rosalind练习题二十七

# Problem
# A partial permutation is an ordering of only k objects taken from a collection containing n objects (i.e., k≤n). For example, one partial permutation of three of the first eight positive integers is given by (5,7,2).
# The statistic P(n,k) counts the total number of partial permutations of k objects that can be formed from a collection of n objects. Note that P(n,n) is just the number of permutations of n objects, which we found to be equal to n!=n(n−1)(n−2)⋯(3)(2) in “Enumerating Gene Orders”.

# Given: Positive integers n and k such that 100≥n>0 and 10≥k>0.
# Return: The total number of partial permutations P(n,k), modulo 1,000,000.

# Sample Dataset
# 21 7
# Sample Output
# 51200

# 这道题目中,给定两个正整数 n 和 k(满足 100≥n>0、10≥k>0),定义 P(n,k) 为从 n 个不同的对象中取 k 个对象进行排列的方案数,其中对象排列的顺序有限制(即只能考虑部分的排列方案),计算并输出 P(n,k) 对 1,000,000 取模后的结果。
# 具体来说,P(n,k) 的计算方式为:P(n,k) = n*(n-1)...(n-k+1)。需要注意的是,该计算结果需要对 1,000,000 取模。

def partial_permutations(n, k):
    # 初始化P(n,k)为1
    P = 1

    # 计算 P(n,k) 为 n*(n-1)* ... *(n-k+1)
    for i in range(n, n - k, -1):
        P = (P * i) % 1000000
    return P

print(partial_permutations(21, 7))
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值