programming-challenges Polynomial coefficients (110506) 题解

组合原理

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <assert.h>
#include <algorithm>
#include <math.h>
#include <ctime>
#include <functional>
#include <string.h>
#include <stdio.h>
#include <numeric>
#include <float.h>

using namespace std;

int C[13][13]; 

void buildC() {
	C[0][0] = 1; 
	for (int i = 1; i <= 12; i++) C[i][0] = 1; 

	for (int i = 1; i <= 12; i++) {
		for (int j = 1; j <= i; j++) { 
			C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; 
		}
	}
}

int main() {
	buildC(); 

	int n, k; 
	while (cin >> n >> k) {
		vector<int> v(k); 
		for (int i = 0; i < k; i++) cin >> v[i]; 

		int ans = 1; 
		for (int i = 0; i < k; i++) {
			ans *= C[n][v[i]]; 
			n -= v[i]; 
		}

		cout << ans << endl; 
	}

	return 0; 
}


你可能感兴趣的:(Algorithm,C++)