鱼C论坛

 找回密码
 立即注册
查看: 6915|回复: 35

[已解决]Python:每日一题 296

[复制链接]
发表于 2019-12-29 20:50:09 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
今天的题目:


给出一个可能包含重复数字的排列,求这些数字的所有排列按字典序排序后该排列在其中的编号。编号从 1 开始。

示例 1:

输入:[1,4,2,2]
输出:3
示例 2:

输入:[1,6,5,3,1]
输:24


欢迎大家一起答题!
最佳答案
2019-12-29 22:01:38
本帖最后由 TJBEST 于 2019-12-30 14:33 编辑

我编了一个最傻的,不过但是如果页数过多,计算机内存有限是无法运算的 哈哈。可能我的算法还有优化的可能性,不过时间不是问题,是数字太大电脑算不出来(我用到了阶乘)
  1. def fun296(arrayGiven):#可重复那就蛋疼了
  2.     def count_sort(array):
  3.         arraysorted = sorted(set(array))#从小打到排序
  4.         arraycount = []#数量
  5.         for eachele in arraysorted:
  6.             arraycount.append(arrayGiven.count(eachele))
  7.         return (arraysorted,arraycount)
  8.             
  9.     def C_mn(m,n):#计算组合数 可以优化
  10.         A = 1
  11.         B = 1
  12.         for i in range(1,n + 1):
  13.             A =A * (m - i +1)
  14.             B = B * i
  15.         return A//B
  16.         
  17.     def lessEle(last,arraysorted,arraycount):#找到 并返回比他小的元素列表
  18.         lessArray = [arraysorted[i] for i in range(0,len(arraysorted)) if arraysorted[i]<last and arraycount[i]>0]
  19.         return lessArray
  20.         
  21.     def chgCount(ele,arraysorted,arraycount):#改变;列表计数
  22.         index = arraysorted.index(ele)
  23.         arraycount[index] = arraycount[index]  - 1
  24.    
  25.     def cal(arraycount,lenth):#计算
  26.         result = 1
  27.         for each in arraycount:
  28.             result = result * C_mn(lenth,each)
  29.             lenth = lenth - each
  30.         return result
  31.    
  32.     if arrayGiven == []:
  33.         return 0
  34.     (arraysorted , arraycount)= count_sort(arrayGiven)
  35.     lenth = len(arrayGiven)
  36.     index = 0
  37.     result = 1
  38.     while index < lenth - 1:
  39.         if index != 0:
  40.             chgCount(arrayGiven[index - 1],arraysorted,arraycount)
  41.         else:
  42.             pass
  43.         lessArray = lessEle(arrayGiven[index],arraysorted,arraycount)
  44.         for eachless in lessArray:
  45.             tempcount = arraycount.copy()
  46.             chgCount(eachless,arraysorted,tempcount)
  47.             result = result + cal(tempcount,lenth - 1 - index)
  48.         index = index + 1
  49.     return result
复制代码

本帖被以下淘专辑推荐:

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-12-29 21:35:35 | 显示全部楼层
本帖最后由 Unicorn# 于 2019-12-30 13:06 编辑

半夜两点写完递归版本,本来想睡了明天再优化,但是没写出来睡不着
第一个是递归版本,支持列表长度<1000,1000时超过递归最大深度
第二个是优化版本,支持列表长度<=2000, 超过2000时数据过大爆栈
猫猫都在我腿上睡着了,溜了溜了
递归版本:
  1. def solve2(nums):
  2.     def transfer(nums):
  3.         res = []
  4.         for each in set(nums):
  5.             res.append((each, nums.count(each)))
  6.         return res
  7.     def C(m, n):
  8.         molecular = 1
  9.         for i in range(m, m-n, -1):
  10.             molecular *= i
  11.         denominator = 1
  12.         for i in range(n, 0, -1):
  13.             denominator *= i
  14.         return int(molecular/denominator)
  15.     def f(nums):
  16.         if len(nums) == 1:
  17.             return 0
  18.         else:
  19.             adder = nums[0]
  20.             n = len(nums)
  21.             a = f(nums[1:])
  22.             nums = transfer(nums)
  23.             choices = list(filter(lambda x:x[0]<adder, nums))
  24.             b = 0
  25.             for choice in choices:
  26.                 count = 1
  27.                 temp = nums.copy()
  28.                 index = temp.index(choice)
  29.                 if temp[index][1] > 1:
  30.                     temp[index] = (temp[index][0], temp[index][1]-1)
  31.                 else:
  32.                     temp.pop(index)
  33.                 l = n - 1
  34.                 for each in temp:
  35.                     count *= C(l, each[1])
  36.                     l -= each[1]
  37.                 b += count
  38.             return a + b
  39.     return f(nums)+1
复制代码

优化版本:
  1. def solve(nums):
  2.     def C(m, n):
  3.         molecular = 1
  4.         for i in range(m, m-n, -1):
  5.             molecular *= i
  6.         denominator = 1
  7.         for i in range(n, 0, -1):
  8.             denominator *= i
  9.         return int(molecular/denominator)
  10.     n = len(nums)
  11.     res = 1
  12.     for i in range(2, n+1):
  13.         temp1 = nums[n-i:]
  14.         adder = temp1[0]
  15.         temp2 = [(i, nums.count(i)) for i in set(temp1)]
  16.         choices = list(filter(lambda x:x[0]<adder, temp2))
  17.         for choice in choices:
  18.             count = 1
  19.             temp3 = temp2.copy()
  20.             index = temp3.index(choice)
  21.             if temp3[index][1] > 1:
  22.                 temp3[index] = (temp3[index][0], temp3[index][1]-1)
  23.             else:
  24.                 temp3.pop(index)
  25.             l = i-1
  26.             for each in temp3:
  27.                 count *= C(l, each[1])
  28.                 l -= each[1]
  29.             res += count
  30.     return res
复制代码

评分

参与人数 1荣誉 +3 鱼币 +3 贡献 +3 收起 理由
zltzlt + 3 + 3 + 3 递归的那个反倒快,101 ms

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-12-29 22:01:38 | 显示全部楼层    本楼为最佳答案   
本帖最后由 TJBEST 于 2019-12-30 14:33 编辑

我编了一个最傻的,不过但是如果页数过多,计算机内存有限是无法运算的 哈哈。可能我的算法还有优化的可能性,不过时间不是问题,是数字太大电脑算不出来(我用到了阶乘)
  1. def fun296(arrayGiven):#可重复那就蛋疼了
  2.     def count_sort(array):
  3.         arraysorted = sorted(set(array))#从小打到排序
  4.         arraycount = []#数量
  5.         for eachele in arraysorted:
  6.             arraycount.append(arrayGiven.count(eachele))
  7.         return (arraysorted,arraycount)
  8.             
  9.     def C_mn(m,n):#计算组合数 可以优化
  10.         A = 1
  11.         B = 1
  12.         for i in range(1,n + 1):
  13.             A =A * (m - i +1)
  14.             B = B * i
  15.         return A//B
  16.         
  17.     def lessEle(last,arraysorted,arraycount):#找到 并返回比他小的元素列表
  18.         lessArray = [arraysorted[i] for i in range(0,len(arraysorted)) if arraysorted[i]<last and arraycount[i]>0]
  19.         return lessArray
  20.         
  21.     def chgCount(ele,arraysorted,arraycount):#改变;列表计数
  22.         index = arraysorted.index(ele)
  23.         arraycount[index] = arraycount[index]  - 1
  24.    
  25.     def cal(arraycount,lenth):#计算
  26.         result = 1
  27.         for each in arraycount:
  28.             result = result * C_mn(lenth,each)
  29.             lenth = lenth - each
  30.         return result
  31.    
  32.     if arrayGiven == []:
  33.         return 0
  34.     (arraysorted , arraycount)= count_sort(arrayGiven)
  35.     lenth = len(arrayGiven)
  36.     index = 0
  37.     result = 1
  38.     while index < lenth - 1:
  39.         if index != 0:
  40.             chgCount(arrayGiven[index - 1],arraysorted,arraycount)
  41.         else:
  42.             pass
  43.         lessArray = lessEle(arrayGiven[index],arraysorted,arraycount)
  44.         for eachless in lessArray:
  45.             tempcount = arraycount.copy()
  46.             chgCount(eachless,arraysorted,tempcount)
  47.             result = result + cal(tempcount,lenth - 1 - index)
  48.         index = index + 1
  49.     return result
复制代码

评分

参与人数 1荣誉 +3 鱼币 +3 贡献 +3 收起 理由
zltzlt + 3 + 3 + 3 101 ms

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-12-29 22:04:22 | 显示全部楼层

我用你这个,答案会出错呢。
  1. >>> solve([1,1,2,1,1])
  2. 5
  3. >>>
复制代码

应该输出 3 呢。
11112->11121->11211->12111->21111
还能有别的排列吗?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-12-29 22:05:20 | 显示全部楼层
本帖最后由 阴阳神万物主 于 2019-12-31 01:41 编辑

抢地板
数学规律,我总算回忆起来了!!!
组合数的计算因为怕超出内存限制,所以就没用杨辉三角,不然还能快一些

  1. def solve(n:'可能包含重复数字的排列')->'编号':
  2.     def a(n,m):#m<=n
  3.         res = 1
  4.         for i in range(n,n-m,-1):
  5.             res *= i
  6.         return res
  7.     def c(n,m):#m<=n
  8.         res = 1
  9.         for i in range(n,m,-1):
  10.             res *= i
  11.         for i in range(n-m,1,-1):
  12.             res //= i
  13.         return res
  14.    
  15.     d = [str(x) for x in n]
  16.     b = dict([(each,d.count(each)) for each in set(d)])
  17.     res = 1
  18.     le = len(d)
  19.     for i in range(le):
  20.         dlt = 0
  21.         le -= 1
  22.         for j in [x for x in b if b[x] and x<d[i]]:
  23.             each = 0
  24.             b[j] -= 1
  25.             an = 0
  26.             for n in b:
  27.                 if b[n] > 1:
  28.                     each = each*c(le,b[n]) if each else c(le,b[n])
  29.                     le -= b[n]
  30.                     dlt -= b[n]
  31.                 elif b[n]:
  32.                     an += 1
  33.             each = each*a(an,an) if each else a(an,an)
  34.             #print('调试',each,b)
  35.             le -= dlt
  36.             dlt = 0
  37.             res += each
  38.             b[j] += 1
  39.         b[d[i]] -= 1
  40.     return res

  41. if __name__ == '__main__':
  42.     print('示例1 输出:',solve([1,4,2,2]))
  43.     print('示例2 输出:',solve([1,6,5,3,1]))
  44.     print('自测 6 输出:',solve([1,2,2,1,1]))
  45.     print('自测 30 输出:',solve([3,2,2,1,1]))
  46.     print('自测大数据,全排列数为c(2000,1000) 输出:',solve([1,2]*1000))
复制代码

这时间复杂度我就有点不会求了。可有人愿意告知于我呀?

排列数公式:

                               
登录/注册后可看大图

组合数公式:

                               
登录/注册后可看大图

评分

参与人数 1荣誉 +1 鱼币 +1 贡献 +1 收起 理由
zltzlt + 1 + 1 + 1

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-12-29 22:16:56 | 显示全部楼层
阴阳神万物主 发表于 2019-12-29 22:04
我用你这个,答案会出错呢。

应该输出 3 呢。

哈哈哈我刚发就知道错了
我在尝试用重复倍率来消掉多余的
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-12-30 01:58:51 | 显示全部楼层
能想出来的最好方案了
才思枯竭 肝到两点
输入数组长度达到1000时超出递归深度限制,1000以内完美运行
明天再写一个列表版的,就没有深度限制了
困死了

  1. def solve2(nums):
  2.     def transfer(nums):
  3.         res = []
  4.         for each in set(nums):
  5.             res.append((each, nums.count(each)))
  6.         return res
  7.     def C(m, n):
  8.         molecular = 1
  9.         for i in range(m, m-n, -1):
  10.             molecular *= i
  11.         denominator = 1
  12.         for i in range(n, 0, -1):
  13.             denominator *= i
  14.         return int(molecular/denominator)
  15.     def f(nums):
  16.         if len(nums) == 1:
  17.             return 0
  18.         else:
  19.             adder = nums[0]
  20.             n = len(nums)
  21.             a = f(nums[1:])
  22.             nums = transfer(nums)
  23.             choices = list(filter(lambda x:x[0]<adder, nums))
  24.             b = 0
  25.             for choice in choices:
  26.                 count = 1
  27.                 temp = nums.copy()
  28.                 index = temp.index(choice)
  29.                 if temp[index][1] > 1:
  30.                     temp[index] = (temp[index][0], temp[index][1]-1)
  31.                 else:
  32.                     temp.pop(index)
  33.                 l = n - 1
  34.                 for each in temp:
  35.                     count *= C(l, each[1])
  36.                     l -= each[1]
  37.                 b += count
  38.             return a + b
  39.     return f(nums)+1
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-12-30 13:55:24 | 显示全部楼层
本帖最后由 Croper 于 2019-12-30 14:06 编辑
  1. def func296(l:list)->int:
  2.     counts=[]
  3.     ret=0
  4.     t=1
  5.     i=0
  6.     for n in reversed(l):
  7.         p,q=0,len(counts)
  8.         while p<q:
  9.             r=(p+q)//2
  10.             if counts[r][0]==n:
  11.                 p=r
  12.                 counts[r][1]+=1
  13.                 break
  14.             elif counts[r][0]>n:
  15.                 q=r
  16.             else:
  17.                 p=r+1
  18.         else:
  19.             counts.insert(p,[n,1])


  20.         for count_pair in counts[:p]:
  21.             ret+=t*count_pair[1]//counts[p][1]

  22.         i+=1
  23.         t*=i
  24.         t//=counts[p][1]

  25.     return ret+1
复制代码

评分

参与人数 1荣誉 +3 鱼币 +3 贡献 +3 收起 理由
zltzlt + 3 + 3 + 3 101 ms

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-12-30 14:39:54 | 显示全部楼层
本帖最后由 fan1993423 于 2019-12-30 14:51 编辑
  1. from math import factorial
  2. from collections import Counter
  3. from copy import deepcopy
  4. def fun295(x):
  5.     if len(x)==len(set(x)):
  6.         length=len(x)
  7.         if length<1:
  8.             return 0
  9.         x_sort=sorted(x)
  10.         initialization=0
  11.         for i in range(length):
  12.             initialization+=x_sort.index(x[i])*factorial(length-i-1)
  13.             x_sort.remove(x[i])
  14.         return initialization+1
  15.     else:
  16.         sort_set_x=sorted(list(set(x)))
  17.         length=len(x)
  18.         initialization=0
  19.         d=deepcopy(x)
  20.         t=1
  21.         for i in range(length):
  22.             index=sort_set_x.index(d[i])
  23.             while index:
  24.                 k=sort_set_x.pop(0)
  25.                 k_index=x.index(k)
  26.                 x.remove(k)
  27.                 shengxia_x=dict(Counter(x)).values()
  28.                 x.insert(k_index,k)
  29.                 for j in shengxia_x:
  30.                     t*=factorial(j)
  31.                 initialization+=factorial(len(x)-1)/t
  32.                 index-=1
  33.             x.pop(0)
  34.             sort_set_x=sorted(list(set(x)))
  35.     return int(initialization)+1
复制代码

评分

参与人数 1荣誉 +1 鱼币 +1 收起 理由
zltzlt + 1 + 1

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-12-30 15:07:19 | 显示全部楼层
另外写个代码少点,但是可能运算量要大的多的代码
  1. from itertools import permutations
  2. def fun295(x):
  3.     k=sorted(list(set(permutations(x))))
  4.     return k.index(tuple(x))+1
复制代码

评分

参与人数 1荣誉 +1 鱼币 +1 收起 理由
zltzlt + 1 + 1 超出内存限制

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-12-30 18:22:11 | 显示全部楼层
本帖最后由 沙里爬 于 2019-12-31 09:54 编辑

不知道满不满足条件
  1. def Factorial(num):
  2.     s=1
  3.     for i in range(1,num+1):
  4.         s *=i
  5.     return s
  6. def geshu(num,lst):
  7.     lst1 = lst.copy()
  8.     lst1.remove(num)
  9.     repetition_num=1
  10.     for i in set(lst1):
  11.         repetition_num *= Factorial(lst1.count(i))
  12.     return Factorial(len(lst1))//repetition_num
  13. def position(num,lst):
  14.     lst1=list(set(lst))
  15.     if len(lst1)==1:
  16.         return 1
  17.     target = lst1.index(num)
  18.     k = 0
  19.     for i in range(target):
  20.         k += geshu(lst1[i],lst)
  21.     return k
  22. def solution(lst):
  23.     k = 0
  24.     lenth=len(lst)
  25.     for i in range(lenth):
  26.         if len(set(lst))==1:
  27.             k+=1
  28.             break
  29.         else:
  30.             k += position(lst[0],lst)
  31.             del lst[0]
  32.     print(k)
复制代码

评分

参与人数 1荣誉 +1 鱼币 +1 贡献 +1 收起 理由
zltzlt + 1 + 1 + 1

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-12-30 18:58:30 | 显示全部楼层
本帖最后由 hfwei0 于 2019-12-31 01:03 编辑
  1. import math,random

  2. def fac(lst0):
  3.     a=1
  4.     for i in range(len(lst0)):
  5.         a*=math.factorial(lst0[i])
  6.     return a

  7. def pmu(lst):
  8.     sk=[]
  9.     sv=[]
  10.     lst1=lst[:]
  11.     lst1.sort()
  12.     n=0
  13.     total=0
  14.     while n < len(lst1):
  15.         tmp=lst1.count(lst1[n])
  16.         if tmp>1:
  17.             sk.append(lst1[n])
  18.             sv.append(tmp)
  19.         n+=tmp
  20.     for i in range(len(lst)):
  21.         temp=lst1.index(lst[i])
  22.         if lst[i] in sk:
  23.             stmp=sk.index(lst[i])
  24.             sv[stmp]-=1
  25.             if sv[stmp] == 1:
  26.                 sk.pop(stmp)
  27.                 sv.pop(stmp)
  28.         total+=temp*(math.factorial(len(lst1)-1)/fac(sv))
  29.         lst1.pop(temp)
  30.     return int(total+1)
  31. c=[]
  32. for i in range(300):
  33.     c.append(random.randint(1,10))
  34. print(pmu(c))
复制代码

print(pmu(c))[/code]只能到300。。。

评分

参与人数 1荣誉 +1 鱼币 +1 贡献 +1 收起 理由
zltzlt + 1 + 1 + 1

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-12-30 19:47:07 From FishC Mobile | 显示全部楼层
fan1993423 发表于 2019-12-30 15:07
另外写个代码少点,但是可能运算量要大的多的代码

这个6诶
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-12-30 21:15:57 | 显示全部楼层
  1. def justcount(list1):
  2.     import itertools
  3.     list2 = list1.copy()
  4.     list2.sort()
  5.     list3 = list(itertools.permutations(list2,len(list2)))
  6.     temp = 0
  7.     while temp < len(list3):
  8.         if list3.count(list3[temp]) > 1:
  9.             temp2 = list3.count(list3[temp])
  10.             temp3 = list3[temp]
  11.             for i in range(temp2):
  12.                 list3.remove(temp3)
  13.             list3.insert(temp,temp3)
  14.         temp += 1
  15.     return list3.index(tuple(list1))+1
复制代码

评分

参与人数 1荣誉 +2 鱼币 +2 贡献 +1 收起 理由
zltzlt + 2 + 2 + 1

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-12-30 21:39:16 | 显示全部楼层
Unicorn# 发表于 2019-12-30 01:58
能想出来的最好方案了
才思枯竭 肝到两点
输入数组长度达到1000时超出递归深度限制,1000以内完美运行

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-12-30 21:40:56 | 显示全部楼层

解答错误

输入:[3,2,2,1,1]
输出:20
预期结果:30
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-12-30 21:43:44 | 显示全部楼层

递归那个快是因为你的测试数据太短了...
我这边测试在输入列表长度超过两百时优化版就有明显优势了(还不会被最大深度限制)
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-12-30 23:58:15 | 显示全部楼层
zltzlt 发表于 2019-12-30 21:40
解答错误

输入:[3,2,2,1,1]

不好意思,刚看了下,忘了重新对t还原为1,在32行添加一句t=1
  1. from math import factorial
  2. from collections import Counter
  3. from copy import deepcopy
  4. def fun295(x):
  5.     if len(x)==len(set(x)):
  6.         length=len(x)
  7.         if length<1:
  8.             return 0
  9.         x_sort=sorted(x)
  10.         initialization=0
  11.         for i in range(length):
  12.             initialization+=x_sort.index(x[i])*factorial(length-i-1)
  13.             x_sort.remove(x[i])
  14.         return initialization+1
  15.     else:
  16.         sort_set_x=sorted(list(set(x)))
  17.         length=len(x)
  18.         initialization=0
  19.         d=deepcopy(x)
  20.         t=1
  21.         for i in range(length):
  22.             index=sort_set_x.index(d[i])
  23.             while index:
  24.                 k=sort_set_x.pop(0)
  25.                 k_index=x.index(k)
  26.                 x.remove(k)
  27.                 shengxia_x=dict(Counter(x)).values()
  28.                 x.insert(k_index,k)
  29.                 for j in shengxia_x:
  30.                     t*=factorial(j)
  31.                 initialization+=factorial(len(x)-1)/t
  32.                 t=1
  33.                 index-=1
  34.             x.pop(0)
  35.             sort_set_x=sorted(list(set(x)))
  36.     return int(initialization)+1
复制代码

评分

参与人数 1荣誉 +2 鱼币 +2 贡献 +1 收起 理由
zltzlt + 2 + 2 + 1

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-12-31 00:31:56 | 显示全部楼层
五楼的地板,代码已更新出来了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-12-31 01:33:27 | 显示全部楼层
本帖最后由 阴阳神万物主 于 2019-12-31 01:42 编辑
Unicorn# 发表于 2019-12-29 21:35
半夜两点写完递归版本,本来想睡了明天再优化,但是没写出来睡不着
第一个是递归版本,支持列 ...

我怀疑你的组合数计算有点小问题。
  1. >>> def C(m, n):
  2.         molecular = 1
  3.         for i in range(m, m-n, -1):
  4.             molecular *= i
  5.         denominator = 1
  6.         for i in range(n, 0, -1):
  7.             denominator *= i
  8.         return int(molecular/denominator)

  9. >>> get = C(200,100)
  10. >>> x = y = z = 1
  11. >>> for i in  range(200,0,-1):
  12.         x *= i

  13.         
  14. >>> for i in range(100,0,-1):
  15.         y *= i

  16.         
  17. >>> for i in range(200-100,0,-1):
  18.         z *= i

  19.         
  20. >>> (x//(y*z)) - get
  21. 484929433446296225432192901808955449760872
  22. >>>  
复制代码

                               
登录/注册后可看大图

严格按照定义公式计算的组合数比你的大好多。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-27 07:58

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表