题目描述

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[],dp[][];
int main()
{
scanf("%d%d",&n,&f);
for(int i=;i<=n;i++)
scanf("%d",&r[i]);
dp[][]=;
for(int i=;i<=n;i++)
for(int j=;j<=f;j++)
{
dp[i][j]+=dp[i-][j]+dp[i-][(j+r[i])%f];
dp[i][j]%=mod;
}
printf("%d\n",dp[n][f]%mod);
return ;
}

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

  1. luogu P2946 [USACO09MAR]牛飞盘队Cow Frisbee Team

    题目背景 老唐最近迷上了飞盘,约翰想和他一起玩,于是打算从他家的N头奶牛中选出一支队伍. 每只奶牛的能力为整数,第i头奶牛的能力为R i .飞盘队的队员数量不能少于 1.大于N.一 支队伍的总能力就是 ...

  2. 牛飞盘队Cow Frisbee Team

    老唐最近迷上了飞盘,约翰想和他一起玩,于是打算从他家的N头奶牛中选出一支队伍. 每只奶牛的能力为整数,第i头奶牛的能力为R i .飞盘队的队员数量不能少于 .大于N. 一支队伍的总能力就是所有队员能力 ...

  3. USACO Cow Frisbee Team

    洛谷 P2946 [USACO09MAR]牛飞盘队Cow Frisbee Team 洛谷传送门 JDOJ 2632: USACO 2009 Mar Silver 2.Cow Frisbee Team ...

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

    3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 89  Solve ...

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

    3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 129  Solv ...

  6. BZOJ 3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 动态规划

    3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=34 ...

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

    Description     农夫顿因开始玩飞盘之后,约翰也打算让奶牛们享受飞盘的乐趣.他要组建一只奶牛飞盘 队.他的N(1≤N≤2000)只奶牛,每只部有一个飞盘水准指数Ri(1≤Ri≤10000 ...

  8. 【BZOJ】3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队(dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3400 既然是倍数我们转换成mod.. 设状态f[i][j]表示前i头牛modj的方案 那么答案显然是 ...

  9. BZOJ 3400 [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队:dp【和为f的倍数】

    题目链接:http://begin.lydsy.com/JudgeOnline/problem.php?id=1375 题意: 给你n个数,你可以从中选任意多个,但不能不选.问你所选数字之和为f的倍数 ...

随机推荐

  1. Easy sssp(spfa)(负环)

    vijos    1053    Easy sssp 方法:用spfa判断是否存在负环 描述 输入数据给出一个有N(2 <= N <= 1,000)个节点,M(M <= 100,00 ...

  2. digits

    Digits(digits.cpp/c/pas)Description给一个关于x的多项式,并给定一个x,求该多项式在带入该x时的值最后k位数字.Input第一行两个整数n.k:之后的 行,每行两个数 ...

  3. OO第三单元作业小结

    一.JML理论基础及应用工具链情况 理论基础 1.JML表达式 \result:表示方法执行后的返回值. \old(expr):表示一个表达式expr在相应方法执行前的取值. \foall:全称量词修 ...

  4. CodeWar----求正整数二进制表示中1的个数

    Codewars Write a function that takes an integer as input, and returns the number of bits that are eq ...

  5. 三角网格上的寻路算法Part.1—Dijkstra算法 等

    http://www.cnblogs.com/chnhideyoshi/p/AStar.html

  6. nuxt.js 加百度统计

    Mark一下: 在 Nuxt.js应用中使用Google统计分析服务,或者百度统计分析服务,推荐在 plugins 目录下创建 plugins/ga.js 文件.统计统计分析我们可以获取网站pv,uv ...

  7. UFLDL教程笔记及练习答案三(Softmax回归与自我学习***)

    :softmax回归 当p(y|x,theta)满足多项式分布,通过GLM对其进行建模就能得到htheta(x)关于theta的函数,将其称为softmax回归. 教程中已经给了cost及gradie ...

  8. Java 递归解决 &quot;仅仅能两数相乘的计算器计算x^y&quot; 问题

    /** * 求一个数的乘方 * 求x^y,y是一个正整数. 设计算器仅仅能计算两数相乘,不能一次计算n个数相乘. * 知:2^5=(2^2)^2*2; 2^6=(2^2)^3=((4)^2)*4; 2 ...

  9. C++ 学习总结 复习篇

      友元的使用 分为友元类和友元函数     //友元类与友元函数的共同点:都可以让某一个类作为另一个类或者函数的参数.          //友元类:它让当前类成为另一个类的友元,然后,另一个类 ...

  10. 使用BatteryHistorian分析和优化应用电量

    欢迎Follow我的GitHub, 关注我的CSDN. 在Android项目中, 较难监控应用的电量消耗, 可是用户却很关心手机的待机时间. 过度耗电的应用, 会遭到用户无情的卸载, 不要存在侥幸心理 ...