lightoj 1125 - Divisible Group Sums
来源:互联网 发布:数据泄露防护系统 编辑:程序博客网 时间:2024/05/22 03:39
Given a list of N numbers you will be allowed to choose any M of them. So you can choose in NCM ways. You will have to determine how many of these chosen groups have a sum, which is divisible byD.
Input
Input starts with an integer T (≤ 20), denoting the number of test cases.
The first line of each case contains two integers N (0 < N ≤ 200) and Q (0 < Q ≤ 10). Here N indicates how many numbers are there and Q is the total number of queries. Each of the next N lines contains one 32 bit signed integer. The queries will have to be answered based on these N numbers. Each of the next Q lines contains two integers D (0 < D ≤ 20) and M (0 < M ≤ 10).
Output
For each case, print the case number in a line. Then for each query, print the number of desired groups in a single line.
Sample Input
Output for Sample Input
2
10 2
1
2
3
4
5
6
7
8
9
10
5 1
5 2
5 1
2
3
4
5
6
6 2
Case 1:
2
9
Case 2:
1
输入N和q,代表有N个数,q次询问,每次询问输入两个数,D和M,代表从N个数中选M个数的和可以被D整除,问有多少种方案。
dp[i][j][k]代表前i个数中选j个,它们的和模D为k。
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define inf 1e9#define endl '\n'#define LL long longusing namespace std;LL dp[210][15][25];int main(void){ int T,n,m,q,d,i,j,k; int a[205]; scanf("%d",&T); int cas = 1; while(T--) { scanf("%d%d",&n,&q); for(i=1;i<=n;i++) scanf("%d",&a[i]); printf("Case %d:\n",cas++); while(q--) { scanf("%d%d",&d,&m); memset(dp,0,sizeof(dp)); dp[0][0][0] = 1; for(i=1;i<=n;i++) { dp[i][0][0] = 1; for(j=1;j<=m;j++) { for(k=0;k<d;k++) { dp[i][j][k] += dp[i-1][j][k]; dp[i][j][k] += dp[i-1][j-1][(k - a[i]%d + d)%d]; } } } printf("%lld\n",dp[n][m][0]); } }}
- lightoj 1125 - Divisible Group Sums
- Divisible Group Sums LightOJ
- LightOJ - 1125 Divisible Group Sums(DP)
- LightOJ 1125 Divisible Group Sums (dp)
- lightoj 1125 - Divisible Group Sums 01背包变形
- 1125 - Divisible Group Sums (DP)
- UVA 10616 Divisible Group Sums
- UVa:10616 Divisible Group Sums
- UVA10616 - Divisible Group Sums(dp)
- UVa 10616 - Divisible Group Sums
- Light oj 1125 - Divisible Group Sums(简单dp)
- Light OJ 1125 Divisible Group Sums (DP)
- uva 10616 - Divisible Group Sums(计数)
- 10616 - Divisible Group Sums(dp背包)
- UVa 10616 Divisible Group Sums (DFS&DP)
- Light OJ 1125 Divisible Group Sums 背包DP 2017/1/23
- lightoj1125:Divisible Group Sums(类01背包)
- POJ 3092 Non-divisible 2-3 Power Sums 笔记
- 在PHP中使用Mysqli操作数据库
- JAVA 网络编程 Socket 详细说明,实现客户端和服务端相互推送消息
- MyBatis学习总结(八)——Mybatis3.x与Spring4.x整合
- eclipse设置默认编码
- mysql安装步骤
- lightoj 1125 - Divisible Group Sums
- laravel基础知识-框架目录文件介绍
- java中的socket编程
- C#调用C++dll方法,char*类型之间的传递
- 【Data Structure】------类型定义
- mysql的约束
- C#控制台基础 自定义类不同实例之间的赋值(引用传递的一个示例)
- 欢迎使用CSDN-markdown编辑器
- Linux学习笔记之RHEL6修改root密码