題 意: 求多項式的某一項。
解法: 二項式定理推廣。
TAG: Math
注意:
程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Tittle: 10105 - Polynomial Coefficients | |
* Author: Cheng-Shih, Wong | |
* Date: 2015/03/22 | |
*/ | |
// include files | |
#include <iostream> | |
#include <cstdio> | |
#include <cstring> | |
using namespace std; | |
// definitions | |
#define FOR(i,a,b) for( int i=(a),_n=(b); i<=_n; ++i ) | |
#define clr(x,v) memset( x, v, sizeof(x) ) | |
#define N 15 | |
// declarations | |
int n, k; | |
int coef[N]; | |
int c[N][N]; | |
int ans; | |
// functions | |
// main function | |
int main( void ) | |
{ | |
// init | |
clr( c, 0 ); | |
FOR( i, 0, 12 ) { | |
c[i][0] = c[i][i] = 1; | |
FOR( j, 1, i-1 ) c[i][j] = c[i-1][j]+c[i-1][j-1]; | |
} | |
// input | |
while( scanf( "%d%d", &n, &k )==2 ) { | |
FOR( i, 1, k ) scanf( "%d", &coef[i] ); | |
// solve | |
ans = 1; | |
FOR( i, 1, k ) { | |
ans *= c[n][coef[i]]; | |
n -= coef[i]; | |
} | |
printf( "%d\n", ans ); | |
} | |
return 0; | |
} |
沒有留言:
張貼留言
任何意見都樂意傾聽