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 ...
随机推荐
- oracle--ORA-27125
一,问题描述 ORA-27125 unable to create shared memory segment 二,问题解决 查看系统的oracleid号 [root@dgwxpdb ~]# id o ...
- 解密httpclient,dbcp,jedis,c3p0,druid,okhttp都在使用的连接池技术
最近在连接池上面栽了个跟头(参见这里),引起我对池技术的强烈关注,这几天总结了一下很多场景都会使用的池技术: 池概念 pool,中文翻译为水池,但是在英文中,还有一种解释是 an organizati ...
- Windows 有没有办法查看文件被哪个进程占用
经常当我们删除文件时,有时会提示[操作无法完成,因为文件已在另一个程序中打开,请关闭该文件并重试],到底是哪些程序呢? 有时候一个一个找真不是办法,已经被这个问题折磨很久了,今天下决心要把它解决,找到 ...
- .NET Core:Json和XML
(1)Json WebAPI默认使用Json格式,如果需要更改默认的Json设置在Startup的ConfigureServices方法中修改:services.AddMvc() .AddJsonOp ...
- 2019 年 Java 最新面试指南共 80 题,赶快收藏起来吧!
2019 年 Java 最新面试指南共 80 题,赶快收藏起来吧! http://blog.zh66.club/index.php/archives/116/
- Docker安装和上传容器
安装Docker Requirements for Mac(硬件要求): Mac的硬件必须是2010或者更新的,需要支持memory management unit(MMU) virtualizait ...
- Laravel手动分页的方法
use Illuminate\Pagination\LengthAwarePaginator; public function index(Request $request){ $list =[... ...
- windows 下验证文件MD5
CertUtil -hashfile C:\Users\admin\Downloads\aaa.txt MD5 CertUtil -hashfile C:\Users\admin\Downloads\ ...
- R与金钱游戏:均线黄金交叉2
从上一篇分析已经得知均线黄金交叉原则并不适用于震荡期,那有什么办法可以规避震荡期呢或者说有什么办法可以减少无脑跟的损失?我们继续玩一下. Required Packages library(quant ...
- Prometheus PromSQL 获取系统服务运行状态
Prometheus PromSQL 获取系统服务运行状态 使用systemd收集器:--collector.systemd.unit-whitelist=".+" 从system ...