UVa Problem Solution: 10105 - Polynomial Coefficients


The coefficient of x1n1x2n2...xknk is (n, n1)(n-n1, n2)...(n-n1-n2-...-nk-1, nk) = n!/n1!n2!...nk!.

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. }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章