题目描述
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.
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).
解答
又是一个dp。
倍数即余数为0。
状态表示前个数里加和余数为的方案数。
个人认为设状态比状态转移更不好想。状态最好设题目中出现的且范围不是很大的量。
倍数即余数为0。
状态表示前个数里加和余数为的方案数。
个人认为设状态比状态转移更不好想。状态最好设题目中出现的且范围不是很大的量。
#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); }
来源:KatnissJ