USACO Cow Frisbee Team

Luo Gu P2946 [USACO09MAR] cattle Frisbee teams Cow Frisbee Team

Luo Gu Portal

JDOJ 2632: USACO 2009 Mar Silver 2.Cow Frisbee Team

JDOJ Portal

Description

After Farmer Don took up Frisbee, Farmer John wanted to join in the
fun. He wants to form a Frisbee team from his N cows (1 <= N <=
2,000) conveniently numbered 1..N. The cows have been practicing
flipping the discs around, and each cow i has a rating R_i (1 <=
R_i <= 100,000) denoting her skill playing Frisbee. FJ can form a
team by choosing one or more of his cows.

However, because FJ needs to be very selective when forming Frisbee
teams, he has added an additional constraint. Since his favorite
number is F (1 <= F <= 1,000), he will only accept a team if the
sum of the ratings of each cow in the team is exactly divisible by

F.

Help FJ find out how many different teams he can choose. Since this
number can be very large, output the answer modulo 100,000,000.

Note: about 50% of the test data will have N <= 19.

Input

* Line 1: Two space-separated integers: N and F

* Lines 2..N+1: Line i+1 contains a single integer: R_i

Output

* Line 1: A single integer representing the number of teams FJ can
choose, modulo 100,000,000.

Sample Input

4 5 1 2 8 2

Sample Output

3

HINT

INPUT DETAILS:

FJ has four cows whose ratings are 1, 2, 8, and 2. He will only accept a
team whose rating sum is a multiple of 5.

OUTPUT DETAILS:

FJ can pair the 8 and either of the 2's (8 + 2 = 10), or he can use both
2's and the 1 (2 + 2 + 1 = 5).

Title Translation:

Laotang recently fell in love Frisbee, John wanted to play with him, he intended to select a team from the N cows in his home.

Each capability is an integer of cows, cows i Ability to R i. Number of players Frisbee teams of not less than 1, greater than N. One

The total capacity of the teams is the sum of all the players abilities.

Compare John superstition, his lucky number is F, so he requested the ability of the team must be a multiple of F. Please help him

Count, the team combined to meet this requirement of how many? Since this number is large, as long as the output answer is divided by 10 ^ 8108

Number on it.

Input Format

 First line: space-separated two integers: N, F, 1 ≤ N ≤ 2000,1 ≤ F ≤ 1000

 second row to row N + 1: i + 1 th line have an integer R i, i denotes the ability of cows, 1 ≤ R i ≤ 10 5

Output Format

 first line of: a single integer, indicates the program number by 10 ^ 8108 remainders

answer:

A very DP content (recursive)

This question of status is set to baffle me.

After long-term solution to a problem + debugging help, I will dp [i] [j] is set to pre-election i cows,% f the number of programs for the remainder of j, note that% f after! !

1 initial condition.

So we need to initialize when r [i] a mold f.

Then the state transition is the code shown.

Come see the answer:

#include<cstdio>
#include<algorithm>
using namespace std;
const int mod=1e8;
int n,f,r[2001];
int dp[2001][1001];
int main()
{
    scanf("%d%d",&n,&f);
    for(int i=1;i<=n;i++)
        scanf("%d",&r[i]);
    for(int i=1;i<=n;i++)
        dp[i][r[i]%f]=1;
    for(int i=1;i<=n;i++)
        for(int j=0;j<f;j++)
            dp[i][j]=(dp[i][j]+dp[i-1][j]+dp[i-1][((j-r[i])%f+f)%f])%mod;
    printf("%d",dp[n][0]);
    return 0;
}

Guess you like

Origin www.cnblogs.com/fusiwei/p/11293681.html