Title Description:
Given two polynomial, the highest power is n and M, respectively, to solve the coefficient array obtained by multiplying these two coefficients.
Analysis:
The highest power if it is M and N, then they multiply the coefficients of the array of the highest power must be n+m, for other coefficients, may wish to set a[],b[] is a given two coefficients array, c[] is the answer array, then:
C[i + j] + = a[i] * B[j];
This is the derivation of the mathematical formula, can be obtained.
Code:
#include <cstdio>#include<iostream>#include<cstring>#include<string>using namespacestd;Const intN = -;intA[n];intB[n];intc[n*2];voidInitintNintm) { for(inti =0; I<n; ++i) {cin>>A[i]; } for(intj =0; j< m; ++j) {cin>>B[j]; }}voidCalintNintm) { for(inti =0; i<= N; ++i) { for(intj =0; J <= m;++j) {C[i+J] + = a[i] *B[j]; } }}voidPrtintNintm) { for(inti =0; I <= n+m;++i) {cout<<"c["<<n+m-i<<"] = "<<c[i]<<Endl; }}intMain () {intn,m; while(cin>>n>>m) {init (n+1, m+1); Cal (N,M); PRT (N,M); }return 0;}
Two polynomial multiplication to solve the coefficient array algorithm