LightOJ1125 Divisible Group Sums
Divisible Group Sums
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 by D.
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
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
Sample Output
Case 1:
2
9
Case 2:
1
从n个数字里面取m个有C(n,m)种取法,问有多少种取法使得总和是D的倍数
因为询问好多组(m,d),所以每次都要对不同的d先取模,然后显然就是个背包啦,数字不超过d,只取m个,最大容量只有200
然后特么给的ai还有负数,,,我真是,,,
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<LL,int>
#define mkp(a,b) make_pair(a,b)
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,q;
int a[];
int b[];
LL f[][];
inline void work(int cur)
{
printf("Case %d:\n",cur);
n=read();q=read();
for (int i=;i<=n;i++)a[i]=read();
for (int i=;i<=q;i++)
{
int mod=read(),m=read();
memset(f,,sizeof(f));f[][]=;
for (int j=;j<=n;j++)b[j]=(a[j]%mod+mod)%mod;
for (int j=;j<=n;j++)
{
for (int k=m;k>=;k--)
for (int l=m*mod;l>=b[j];l--)
f[k][l]+=f[k-][l-b[j]];
}
LL sum=;
for (int j=;j<=m*mod;j+=mod)sum+=f[m][j];
printf("%lld\n",sum);
}
}
int main()
{
int T=read(),tt=;
while (T--)work(++tt);
}
LightOJ 1125
LightOJ1125 Divisible Group Sums的更多相关文章
- LightOJ1125 Divisible Group Sums(DP)
题目问从N个数中取出M个数,有多少种取法使它们的和能被D整除. dp[i][j][k]表示,前i个数取出j个数模D的余数为k的方案数 我用“我为人人”的方式来转移,就从i到i+1转移,对于第i+1个数 ...
- Light oj 1125 - Divisible Group Sums (dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1125 题意: 给你n个数,q次询问,每次询问问你取其中m个数是d的整数倍的方案 ...
- Divisible Group Sums
Divisible Group Sums Given a list of N numbers you will be allowed to choose any M of them. So you c ...
- lightoj 1125 - Divisible Group Sums (dp)
Given a list of N numbers you will be allowed to choose any M of them. So you can choose in NCM ways ...
- UVa 10616 - Divisible Group Sums
称号:给你n数字.免去m一个,这使得他们可分割d.问:有多少种借贷. 分析:dp,D01背包. 背包整数分区. 首先.整点d.则全部数字均在整数区间[0,d)上: 然后,确定背包容量,最大为20*10 ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- 一位学长的ACM总结(感触颇深)
发信人: fennec (fennec), 信区: Algorithm 标 题: acm 总结 by fennec 发信站: 吉林大学牡丹园站 (Wed Dec 8 16:27:55 2004) AC ...
- lightoj刷题日记
提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...
- [Swift]LeetCode974. 和可被 K 整除的子数组 | Subarray Sums Divisible by K
Given an array A of integers, return the number of (contiguous, non-empty) subarrays that have a sum ...
随机推荐
- js 两个数组进行去重处理,返回去重后的数组
1.去重的方法为: array_diff(a, b) { for (var i = 0; i < b.length; i++) { for (var j = 0; j < a.length ...
- CVE-2010-3333
环境 windows xp sp3 office 2003 sp0 windbg ollydbg vmware 12.0 0x00 RTF格式 RTF是Rich TextFormat的缩写,意即富文本 ...
- (转发)IOS高级开发~Runtime(一)
IOS高级开发-Runtime(一) IOS高级开发-Runtime(二) IOS高级开发-Runtime(三) IOS高级开发-Runtime(四) 一些公用类: @interface Custom ...
- PLAYGROUND 可视化
PLAYGROUND 可视化 由 王巍 (@ONEVCAT) 发布于 2015/09/23 在程序界,很多小伙伴都会对研究排序算法情有独钟,并且试图将排序执行的过程可视化,以便让大家更清晰直观地了解算 ...
- Vue开发微信公众号默认背景为灰色
最近公司有一个项目,使用Vue开发微信公众号,开发过程遇到一个问题,即设计图的整体背景是白色的,但是公众号里默认的背景是浅灰色,如果某个页面高度没能占满一屏,就会露出浅灰色的默认背景,会显得很不协调. ...
- 【OS_Linux】三大文本处理工具之grep命令
grep(global search regular expression(RE) and print out the line,整行搜索并打印匹配成功的行 语法:grep [选项] 搜索词 ...
- https原理解读
参考:架构师必读!以图文的方式解锁 HTTPS原理,10分钟还原HTTPS真像! 对于消息安全的定义是:即使消息被中间人拦截到,中间人也没办法解读出其中的消息. 对称加密 要实现消息安全,首先想到的是 ...
- perl学习之子程序
一.定义子程序即执行一个特殊任务的一段分离的代码,它可以使减少重复代码且使程序易读.PERL中,子程序可以出现在程序的任何地方.定义方法为:sub subroutine{statements;}二.调 ...
- Oracle联合主键
转https://www.cnblogs.com/king-xg/p/6721272.html alter table tablename add constraint unionkeyname pr ...
- map函数的应用:UVa156-Ananagrams
Ananagrams Most crossword puzzle fans are used to anagrams - groups of words with the same letters i ...