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 ...
随机推荐
- PDMan-2.1.0 正式发布:用心开源,免费的国产数据库建模工具 PowerDesigner
PDMan是一款开源免费的数据库模型建模工具,支持Windows,Mac,Linux等操作系统,是PowerDesigner之外,更好的免费的替代方案.他具有颜值高,使用简单的特点.包含数据库建模,灵 ...
- pyqt助手中安装Qt帮助文档
一.个人安装环境 1.Windows7x64_SP1 2.anaconda2.5.0 + python2.7(anaconda集成,不需单独安装) 3.pyinstaller3.0 4.通过Anaco ...
- linux _文件目录与权限
1. 目录相关 . 代表次层目录 .. 代表上一层目录 - 代表前一个工作目录 ~ 代表目前使用者身份所在home目录 ~account 代表account这个使用者的home目录 cd 切换目录(c ...
- numpy delete方法
import numpy as np lines = np.loadtxt(r'./test.txt',delimiter=',',dtype=int) print(lines) lines_copy ...
- luogu P2495 [SDOI2011]消耗战 |虚树+LCA+dp
题目描述 在一场战争中,战场由n个岛屿和n-1个桥梁组成,保证每两个岛屿间有且仅有一条路径可达.现在,我军已经侦查到敌军的总部在编号为1的岛屿,而且他们已经没有足够多的能源维系战斗,我军胜利在望.已知 ...
- python做一个简易图片下载工具
代码有点乱,先这样 # -*- coding:utf-8 -*- #__author__ :kusy #__content__:文件说明 #__date__:2018/11/01 11:01 impo ...
- 如何在 ubuntu 下使用 Windows 里面的字体
01. 02. 03. 04. 谢谢浏览!
- KVM虚拟机典型配置文件xml
<domain type='kvm'> <name>vm64-1</name> //虚拟机名称 <memory unit='MiB'>2300</ ...
- js展示long型精度问题解决(server端解决)
问题:后端返回了个Long型的数据,在前端展示时最后2位变为00了 例如返回Long型的数据为75874464836881101,结果接口返回变为75874464836881100了 解决方法: 1. ...
- Vue-员工管理系统
大二暑假进行了两周Vue的入门学习,主要内容就是关于前端的入门学习,在两周内学习了Vue的一些简单使用 主要就是使用数据的双向绑定,使用Vue进行数据处理,使用Bootstrap进行布局搭建,下面是我 ...