USACO Cow Frisbee Team
洛谷 P2946 [USACO09MAR]牛飞盘队Cow Frisbee Team
JDOJ 2632: USACO 2009 Mar Silver 2.Cow Frisbee Team
Description
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.
Input
* Line 1: Two space-separated integers: N and F
* Lines 2..N+1: Line i+1 contains a single integer: R_i
Output
* Line 1: A single integer representing the number of teams FJ can
choose, modulo 100,000,000.
Sample Input
4 5 1 2 8 2
Sample Output
3
HINT
INPUT DETAILS:
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.
OUTPUT DETAILS:
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头奶牛中选出一支队伍。
每只奶牛的能力为整数,第i头奶牛的能力为R i 。飞盘队的队员数量不能少于 1、大于N。一
支队伍的总能力就是所有队员能力的总和。
约翰比较迷信,他的幸运数字是F,所以他要求队伍的总能力必须是F的倍数。请帮他
算一下,符合这个要求的队伍组合有多少?由于这个数字很大,只要输出答案除以10^8108 的余
数就可以了。
输入格式
第一行:两个用空格分开的整数:N和F,1 ≤ N ≤ 2000,1 ≤ F ≤ 1000
第二行到N + 1行:第i + 1行有一个整数R i ,表示第i头奶牛的能力,1 ≤ R i ≤ 10 5
输出格式
第一行:单个整数,表示方案数除以10^8108 的余数
题解:
一道非常有含量的DP(递推)
这道题的状态设置把我难倒了。
经过长期调试+题解帮助,我将dp[i] [j]设置成选前i头奶牛,%f余数为j的方案数,注意,是%f之后!!
初始条件为1.
所以我们初始化的时候需要把r[i]模一个f。
然后状态转移就是如代码所示了。
来吧看答案:
#include<cstdio>
#include<algorithm>
using namespace std;
const int mod=1e8;
int n,f,r[2001];
int dp[2001][1001];
int main()
{
scanf("%d%d",&n,&f);
for(int i=1;i<=n;i++)
scanf("%d",&r[i]);
for(int i=1;i<=n;i++)
dp[i][r[i]%f]=1;
for(int i=1;i<=n;i++)
for(int j=0;j<f;j++)
dp[i][j]=(dp[i][j]+dp[i-1][j]+dp[i-1][((j-r[i])%f+f)%f])%mod;
printf("%d",dp[n][0]);
return 0;
}
USACO Cow Frisbee Team的更多相关文章
- BZOJ3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队
3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 89 Solve ...
- 3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队
3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 129 Solv ...
- BZOJ 3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 动态规划
3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=34 ...
- P2946 [USACO09MAR]牛飞盘队Cow Frisbee Team
题目描述 After Farmer Don took up Frisbee, Farmer John wanted to join in the fun. He wants to form a Fri ...
- BZOJ 3400 [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队:dp【和为f的倍数】
题目链接:http://begin.lydsy.com/JudgeOnline/problem.php?id=1375 题意: 给你n个数,你可以从中选任意多个,但不能不选.问你所选数字之和为f的倍数 ...
- 牛飞盘队Cow Frisbee Team
老唐最近迷上了飞盘,约翰想和他一起玩,于是打算从他家的N头奶牛中选出一支队伍. 每只奶牛的能力为整数,第i头奶牛的能力为R i .飞盘队的队员数量不能少于 .大于N. 一支队伍的总能力就是所有队员能力 ...
- P3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队
太水了,背包DP. (转载请注明出处:http://www.cnblogs.com/Kalenda/) ; var n,f,i,j,ans,t,tt:longint; q:array[..] of l ...
- bzoj:3400 [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队
Description 农夫顿因开始玩飞盘之后,约翰也打算让奶牛们享受飞盘的乐趣.他要组建一只奶牛飞盘 队.他的N(1≤N≤2000)只奶牛,每只部有一个飞盘水准指数Ri(1≤Ri≤10000 ...
- [USACO09MAR]Cow Frisbee Team
嘟嘟嘟 这个是一个很明显的dp,遇到这种倍数的问题的,就令dp[i][j]表示选到了第 i 只牛(不是选了 i 只牛),sum(Ri) % f == j 的方案数,则, dp[i][j] = dp[i ...
随机推荐
- quartz Cron表达式生成详解
简介 Cron作为一个Unix工具,已经存在很长一段时间了,用于实现任务调度的功能.CronTrigger类基于Cron而来. CronTrigger CronTriggers往往比SimpleTri ...
- Visual Studio 2019(VS2019)正式版注册码秘钥
Visual Studio 2019 EnterpriseBF8Y8-GN2QH-T84XB-QVY3B-RC4DF Visual Studio 2019 ProfessionalNYWVH-HT4X ...
- Python 标准数据类型
标准数据类型: Number(数字)----int float bool complex(复数) String(字符串) List(列表) Tuple(元组) Dictionary(字典) Set(集 ...
- CSS3幸运大转盘最简单的写法
点击开始 直接css动画 如果你要自己控制转到哪里 那就多写几个class 根据不同角度 运行不同的class..<pre>.zhuandong{ animation: zhuandong ...
- Ubuntu16 安装 wireshark
添加源 sudo apt-add-repository ppa:wireshark-dev/stable 更新 sudo apt-get update 安装 sudo apt-get install ...
- IDEA Rider 准备试用一段时间(1)
IDEA Rider是一个C#开发工具,目前最高版本支持C# 8.0语法. IDEA Rider2019.2月版本相比之前2018版本多了新功能,又支持Edit and Continue,所以准备试用 ...
- 设置a标签,实现点击跳转页面的两种效果
设置a标签,实现点击跳转页面 这个问题,主要是设置a标签的属性target,下面对target属性进行描述: 跳转在同一个窗口 1,target="_self", 它使得目标文档 ...
- Java8 Optional总结
分类专栏: Java 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/HEYUTAO00 ...
- Exceptionless - 本地搭建
搭建环境:Windows 10 参与文档:https://github.com/exceptionless/Exceptionless/wiki/Self-Hosting 运行环境: .NET 4.6 ...
- 使用Docker Compose 部署Nexus后提示:Unable to create directory /nexus-data/instance
场景 Ubuntu Server 上使用Docker Compose 部署Nexus(图文教程): https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/ ...