UVa Problem Solution: 10105 - Polynomial Coefficients


The coefficient of x 1 n1x 2 n2...x k nk is (n, n 1)(n-n 1, n 2)...(n-n 1-n 2-...-n k-1, n k) = n!/n 1!n 2!...n k!.

Code:
  1. /*************************************************************************
  2.  * Copyright (C) 2008 by liukaipeng                                      *
  3.  * liukaipeng at gmail dot com                                           *
  4.  *************************************************************************/
  5. /* @JUDGE_ID 00000 10105 C++ "Polynomial Coefficients" */
  6. #include <algorithm>
  7. #include <cstdio>
  8. #include <cstring>
  9. #include <deque>
  10. #include <fstream>
  11. #include <iostream>
  12. #include <list>
  13. #include <map>
  14. #include <queue>
  15. #include <set>
  16. #include <stack>
  17. #include <string>
  18. #include <vector>
  19. using namespace std;
  20.           
  21. int main(int argc, char *argv[])
  22. {
  23. #ifndef ONLINE_JUDGE
  24.   freopen((string(argv[0]) + ".in").c_str(), "r", stdin);
  25.   freopen((string(argv[0]) + ".out").c_str(), "w", stdout);
  26. #endif
  27.   int factorials[] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880,
  28.                       3628800, 39916800, 479001600};
  29.   for (int n, k; cin >> n >> k; ) {
  30.     int c = factorials[n];
  31.     for (int i = 0, t; i < k && cin >> t; ++i)
  32.       c /= factorials[t];
  33.     cout << c << '/n';
  34.   } 
  35.   return 0;
  36. }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值