POJ3046 Ant Counting "female function"

Source: Internet
Author: User

Ant counting
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2924 Accepted: 1170

Description

Bessie was poking around, the Ant Hill one day watching the ants march to and fro while gathering food. She realized that many of the ants were siblings, indistinguishable from one another. She also realized the sometimes only one ant would go for food, sometimes a few, and sometimes all of them. This made for a large number of different sets of ants!

Being a bit mathematical, Bessie started wondering. Bessie noted that the hive has T (1 <= T <= $) families of ants which she labeled 1..T (A ants altogether). Each family had some number Ni (1 <= ni <=) of ants.

How many groups of sizes S, s+1, ..., b (1 <= S <= B <= A) can be formed?

While observing one group, the set of three ant families is seen as {1, 1, 2, 2, 3}, though rarely in that order. The possible sets of marching ants were:

3 sets with 1 ant: {1} {2} {3}
5 Sets with 2 ants: {1,3} {2,2} {2,3}
5 Sets with 3 ants: {1,1,2} {1,1,3} {1,2,2} {+-*} {2,2,3}
3 Sets with 4 ants: {1,2,2,3} {1,1,2,2} {1,1,2,3}
1 set with 5 ants: {1,1,2,2,3}

Your job is to count the number of possible sets of ants given the data above.

Input

* Line 1:4 space-separated integers:t, A, S, and B

* Lines 2..a+1:each line contains A single integer that's an ant type present in the hive

Output

* Line 1:the number of sets of size S.. B (inclusive) that can is created. A set like {same} is the, the set {2,1} and should not being double-counted. Print only the last SIX DIGITS of this number, with no leading zeroes or spaces.

Sample Input

3 5 2 312213

Sample Output

10

Hint

INPUT DETAILS:

Three types of ants (1..3); 5 ants altogether. How many sets of size 2 or size 3 can be made?


OUTPUT DETAILS:

5 sets of ants with the members; 5 more sets of ants with three members

Source

Usaco 2005 November Silver

Female function Version: 344ms

#include <stdio.h> #include <algorithm> #include <string.h>using namespace std;const int mod = 1000000; const int MAXN = 1002;const int maxm = 100002;int DP[MAXM], ARR[MAXN], C1[MAXM], C2[maxm];int main () {int T, A, S, B,    I, J, K, V, sum;        while (scanf ("%d%d%d%d", &t, &a, &s, &b)! = EOF) {memset (arr, 0, sizeof (int) * (T + 1));            for (i = 0; i < A; ++i) {scanf ("%d", &v);        ++ARR[V];        } memset (c1, 0, sizeof (int) * (B + 1));        memset (c2, 0, sizeof (int) * (B + 1));        C1[0] = 1;  for (i = 1; l <= T; ++i) {for (j = 0; J <= B; ++j) for (k = 0; k <= Arr[i] && k + J <= B;                ++K) C2[j+k] = (C1[j] + c2[j+k])% MoD;                for (j = 0; J <= B; ++j) {c1[j] = C2[j]; C2[j] = 0;        }} for (sum = 0, i = S; I <= B; ++i) sum = (sum + c1[i])% MoD; printf ("%d\n", sum); } return 0;}


POJ3046 Ant Counting "female function"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.