P2946 [USACO09MAR]牛飞盘队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 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.

农夫顿因开始玩飞盘之后,约翰也打算让奶牛们享受飞盘的乐趣.他要组建一只奶牛飞盘

队.他的N(1≤N≤2000)只奶牛,每只部有一个飞盘水准指数Ri(1≤Ri≤100000).约翰要选出1只或多于1只奶牛来参加他的飞盘队.由于约翰的幸运数字是F(1≤F≤1000),他希望所有奶牛的飞盘水准指数之和是幸运数字的倍数.

帮约翰算算一共有多少种组队方式.

输入输出格式

输入格式:

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

输出格式:

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

输入输出样例

输入样例#1:

4 5
1
2
8
2

输出样例#1:

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

【题目大意】

从n个数中选出几个数使他成为f的倍数的方案数。

【思路】

动态规划...

dp[i][j]表示前i个牛,选择的牛的数的和%f==j的方案数。不是很懂转移方程+r[i]不是-r[i]

【code】

#include<iostream>
#include<cstdio>
using namespace std;
#define mod 100000000
int n,f;
int r[2001],dp[2001][1009];
int main()
{
    scanf("%d%d",&n,&f);
    for(int i=1;i<=n;i++)
    scanf("%d",&r[i]);
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
    for(int j=0;j<=f;j++)
    {
        dp[i][j]+=dp[i-1][j]+dp[i-1][(j+r[i])%f];
        dp[i][j]%=mod;
    }
    printf("%d\n",dp[n][f]%mod);
    return 0;
}
时间: 2024-11-09 10:25:34

P2946 [USACO09MAR]牛飞盘队Cow Frisbee Team的相关文章

[USACO09MAR]牛飞盘队Cow Frisbee Team

传送门:https://www.luogu.org/problem/P2946 本题类似于01背包,定义  dp[i][j]  表示前  i  个牛,总和取模幸运值为  j  时的数量,a[i]为第j头牛的能力值,很明显dp[i][j]+=dp[i-1][j](不选择第i头牛)+dp[i-1][(j-a[i]+幸运值)%幸运值](选择第i头牛),这样就可以推出dp[n][0]第n头牛时余数为 0  的数量 1 #include<bits/stdc++.h> 2 using namespace

牛飞盘队Cow Frisbee Team

老唐最近迷上了飞盘,约翰想和他一起玩,于是打算从他家的N头奶牛中选出一支队伍. 每只奶牛的能力为整数,第i头奶牛的能力为R i .飞盘队的队员数量不能少于 1.大于N. 一支队伍的总能力就是所有队员能力的总和. 约翰比较迷信,他的幸运数字是F,所以他要求队伍的总能力必须是F的倍数.请帮他 算一下,符合这个要求的队伍组合有多少?由于这个数字很大,只要输出答案除以 10^8的余 数就可以了. 输入格式 ?第一行:两个用空格分开的整数:N和F,1≤N≤2000,1≤F≤1000 ?第二行到N+1行:第

3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队

3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 129  Solved: 84[Submit][Status][Discuss] Description 农夫顿因开始玩飞盘之后,约翰也打算让奶牛们享受飞盘的乐趣.他要组建一只奶牛飞盘 队.他的N(1≤N≤2000)只奶牛,每只部有一个飞盘水准指数Ri(1≤Ri≤100000).约翰要选出1只或多于1只奶牛来参加他的

BZOJ3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队

3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 89  Solved: 60[Submit][Status] Description 农夫顿因开始玩飞盘之后,约翰也打算让奶牛们享受飞盘的乐趣.他要组建一只奶牛飞盘 队.他的N(1≤N≤2000)只奶牛,每只部有一个飞盘水准指数Ri(1≤Ri≤100000).约翰要选出1只或多于1只奶牛来参加他的飞盘队.由于约翰的幸

BZOJ(begin) 1375 [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队:dp【和为f的倍数】

题目链接:http://begin.lydsy.com/JudgeOnline/problem.php?id=1375 题意: 给你n个数,你可以从中选任意多个,但不能不选.问你所选数字之和为f的倍数的方案数. 题解: 表示状态: dp[i][j] = num of ways i:考虑到第i个数(还没选) j:之前所选数之和 MOD f == j 找出答案: ans = dp[n][0] - 1 不选也是一种方案,但题目种要求不能不选,所以-1. 如何转移: 选或不选第i个数. dp[i+1][

P3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队

太水了,背包DP. 1 const maxn=100000000; 2 var n,f,i,j,ans,t,tt:longint; 3 q:array[0..3000] of longint; 4 a:array[0..3000,0..2000] of longint; 5 begin 6 readln(n,f); 7 for i:=1 to n do 8 begin 9 readln(q[i]); 10 q[i]:=q[i] mod f; 11 end; 12 a[0,0]:=1; 13 fo

小结:动态规划

概要: 状态.转移:最优子结构.无后效性. 技巧及注意: dp就是纯经验+智商题 在dp方程写出来后,一定要考虑边界!不要以为转移对了就行了! 滚动数组的话一定要考虑好顺序! 下标有时候可以灵活使用!比如mod意义下的dp,倍数什么.可到达性等题目都可以这样做. 如果是线性序列的max{f[k]},k<i这种可以用线段树或bit维护成log 注意“前i”和“第i”的区别(特别对于答案更新),有时换一种就能解答出问题. 在状态加限制条件,如单调.地址等. 用下标来维护下标这个答案是否可达. 博弈论

POJ 1946 Cow Cycling

Cow Cycling Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 2516   Accepted: 1396 Description The cow bicycling team consists of N (1 <= N <= 20) cyclists. They wish to determine a race strategy which will get one of them across the fin

ACM学习历程——UVA540 Team Queue(队列,map:Hash)

Description Team Queue   Team Queue  Queues and Priority Queues are data structures which are known to most computer scientists. The Team Queue, however, is not so well known, though it occurs often in everyday life. At lunch time the queue in front