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).
dp[i][j]表示前i个数,价值和%f为j的方案数
注意是加
1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #include<cmath>
5 #include<algorithm>
6 #define lli long long int
7 using namespace std;
8 const int MAXN=2001;
9 const int maxn=0x7fffffff;
10 void read(int &n)
11 {
12 char c='+';int x=0;bool flag=0;
13 while(c<'0'||c>'9'){c=getchar();if(c=='-')flag=1;}
14 while(c>='0'&&c<='9')
15 x=(x<<1)+(x<<3)+c-48,c=getchar();
16 flag==1?n=-x:n=x;
17 }
18 int n,f;
19 int a[MAXN];
20 int dp[MAXN][MAXN];
21 int tot=0;
22 int main()
23 {
24 read(n);read(f);
25 int mod=1e8;
26 for(int i=1;i<=n;i++)
27 read(a[i]);
28 dp[0][0]=1;
29 for(int i=1;i<=n;i++)
30 {
31 for(int j=0;j<=f;j++)
32 {
33 dp[i][j]+=dp[i-1][j];
34 // if(((j-a[i])%f))
35 dp[i][j]+=dp[i-1][(j+a[i])%f];
36 dp[i][j]%=mod;
37 }
38 }
39 cout<<dp[n][f]%mod;
40 return 0;
41 }
- Attribute(特性),怎么用才更好? —— 字段编号被误解了
- PDF.NET的SQL日志 ASP.net 路径问题 详解
- 【自然框架】稳定版beta1——源码下载,Demo说明
- TOP语句放到表值函数外,效率异常低下的原因分析
- 常见.NET功能代码汇总 (3) 33,彻底关闭Excel进程
- Vue.js 入门指南之“前传”(含sublime text 3 配置) 1,下载安装Node.js2,配置Vue环境3,Vue初探4,配置sublime Text
- JavaScript的“原型甘露”
- JSP开发过程遇到的中文乱码问题及解决方法
- 求连续操作(登录)数量(次数)最大的记录(用户)
- 使用Topshelf创建自宿主的Windows服务程序
- 如何用ORM支持SQL语句的CASE WHEN?
- 条件表达式的短路求值与函数的延迟求值
- 使用CTE解决复杂查询的问题
- WinDbg调试.NET程序入门
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Ubuntu E: 无法获得锁 /var/lib/dpkg/lock-frontend – open (11: 资源暂时不可用)
- Ubuntu 18.04 安装MySQL时未提示输入密码的问题及解决方法
- ubuntu中修改grub的启动时间生成
- linux7下虚拟主机的三种实现方式
- 详解CentOS7下PostgreSQL 11的安装和配置教程
- CentOS下安装Memcached和PHP Memcached扩展
- Mac中文件权限查看和设置详解
- linux下open-vswitch安装卸载操作
- CentOS7安装GUI界面及远程连接的实现
- Centos7.4环境安装lamp-php7.0教程
- iOS摄像头推流(2)
- ubuntu 16.04LTS 开机启动自动更换壁纸的实现方法
- linux中Centos7的LVM磁盘扩容问题
- 如何禁止网站内容被搜索引擎收录的几种方法讲解
- Apache由http自动跳转到https的多种方法