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 ...
随机推荐
- shiro : java.lang.IllegalArgumentException: Odd number of characters.
shiro使用的时候: java.lang.IllegalArgumentException: Odd number of characters. at org.apache.shiro.cod ...
- activeandroid复制本地数据库问题总结
activeandroid no such table 解决activeandroid no such table failed to read row 0 column 1 from a curso ...
- Ubuntu 16.04下Java环境安装与配置
首先下载linux下的安装包 登陆网址https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.h ...
- 【转】Python 访问 HDFS
1.前言 hdfs , Hadoop Distributed File System.Hadoop的分布式文件系统,安全行和扩展性没得说. 访问HDFS的方式有以下几种: 命令行方式:FS Shell ...
- 【转】CPU个数,核心数,线程数
我们在买电脑的时候,经常会看cpu的参数,对cpu的描述有这几种:“双核”.“双核四线程”.“四核”.“四核四线程”.“四核8线程”……. 我们接触的电脑基本上都只有一个cup.cpu的个数很容易得到 ...
- SniperOJ-leak-x86-64
参考:1.借助DynELF实现无libc的漏洞利用小结 2.一步一步学ROP之linux_x64篇 - 蒸米 题目源码 #include <stdio.h> #include <un ...
- 浅谈 Swift 2 中的 Objective-C 指针
浅谈 Swift 2 中的 Objective-C 指针 2015-09-07 499 文章目录 1. 在 Swift 中读 C 指针 2. 在 Swift 中创建 C 指针 3. 总结 作者:Ja ...
- 初涉平衡树「treap」
treap:一种平衡的二叉搜索树 什么是treap(带旋) treap=tree+heap,这大家都知道.因为二叉搜索树(BST)非常容易被卡成一条链而影响效率,所以我们需要一种更加平衡的树形结构,从 ...
- database---many to many relationships(多对多关系型数据库)
Many to many Relationships A many-to-many relationship occurs when multiple records in a table are a ...
- vue源码构建代码分析
这是xue源码学习记录,如有错误请指出,谢谢!相互学习相互进步. vue源码目录为 vue ├── src #vue源码 ├── flow #flow定义的数据类型库(vue通过flow来检测数据类型 ...