NC24839. [USACO 2009 Mar S]Cow Frisbee Team
描述
输入描述
* 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.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); }