110506 Polynomial coefficients

来源:互联网 发布:hadoop基础教程 python 编辑:程序博客网 时间:2024/06/05 06:41


#include <iostream>using namespace std;static int C(int n, int k){if (k == 0)return 1;int a = 1, b = 1;for (int i = 1; i <= k; ++i){b *= i;a *= n;--n;}return a / b;}static int Calcualte(int* coeffs, int k, int n){if (k == 1)return C(n, coeffs[0]);return C(n, coeffs[k - 1]) * Calcualte(coeffs, k - 1, n - coeffs[k - 1]);}static void RunTest(int n, int k){int* coeffs = new int[k];for (int i = 0; i < k; ++i)cin >> coeffs[i];cout << Calcualte(coeffs, k, n) << endl;delete[] coeffs;}static void Test(){int n, k;while(cin >> n >> k)RunTest(n, k);}int main(int argc, char* argv[]){Test();return 0;}


原创粉丝点击