列表

详情


NC24839. [USACO 2009 Mar S]Cow Frisbee Team

描述

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 Ri (1 <= Ri <= 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.

输入描述

* Line 1: Two space-separated integers: N and F
* Lines 2..N+1: Line i+1 contains a single integer: Ri

输出描述

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

示例1

输入:

4 5
1
2
8
2

输出:

3

说明:

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.
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).

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++11(clang++ 3.9) 解法, 执行用时: 17ms, 内存消耗: 6376K, 提交时间: 2020-04-03 08:56:53

#include<stdio.h>
#define mod 100000000
int n,m;
int f[2005][1005];
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		x%=m;
		f[i][x]=1;
		for(int j=0;j<m;j++)
		{
			f[i][j]=(f[i][j]+f[i-1][j])%mod;
			f[i][(j+x)%m]=(f[i][(j+x)%m]+f[i-1][j])%mod;
		}
	}
	printf("%d",f[n][0]%mod);
}

上一题