Poj 3046 Ant Counting polynomial Multiplication
Question:
Calculate the number of reorganizations.
Analysis:
The Application of Polynomial multiplication to coefficient calculation, without dp.
Code:
// Poj 3046 // sep9 # include
Using namespace std; const int maxN = 1024; const int maxL = 100024; const int mod = 1000000; int num [maxN]; int coef [maxL]; int tmp [maxL]; int l1; void mul (int l2) {for (int I = 0; I <= l1 + l2; ++ I) tmp [I] = 0; for (int I = 0; I <= l1; ++ I) for (int j = 0; j <= l2; ++ j) tmp [I + j] = (tmp [I + j] + coef [I]) % mod; l1 + = l2; for (int I = 0; I <= l1; ++ I) coef [I] = tmp [I];} int main () {int t, a, s, B; memset (num, 0, sizeof (num); scanf ("% d", & t, & a, & s, & B); while (--) {int x; scanf ("% d", & x); ++ num [x];} memset (coef, 0, sizeof (coef )); coef [0] = 1; l1 = 0; for (int I = 1; I <= t; ++ I) mul (num [I]); int ans = 0; for (int I = s; I <= B; ++ I) ans = (ans + coef [I]) % mod; printf ("% d \ n ", ans); return 0 ;}