Hrbust 2325 Astonishing Combinatorial Number【前缀和+暴力】
来源:互联网 发布:淘宝店铺监管会怎么样 编辑:程序博客网 时间:2024/05/16 04:34
The combinatorial number CmnCnm in combinatorics, where it gives the number of the ways, disregarding order,
the m objects can be chosen from among n objects; more formally, the number of m-element subsets (or m-combinations)
of an n-element set.
Now, there's a simple problem about this number:
For three given number n, m and k, how many pairs of (i, j) will make the equation A.a be true. (0 <= i <= n, 0 <= j <= min(i, m))
Equation A.1:
Cjimodk=0Cijmodk=0
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases.
For each test case:
The first line contains two integers t(1<=t<=10^4) and k(1<=k<=30).
Each of the next t lines contains two integers n(1<=n<=2000) and m(1<=m<=2000) .
1 2
3 3
2 5
4 5
6 7Sample Output
1
0
7
HintIn first test case, only C12=2C21=2 is multiple of 2.Source"尚学堂杯"哈尔滨理工大学第七届程序设计竞赛题目大意:
给你t个查询,每个查询询问Ci,j%k==0的个数(i<=n,j<=min(m,i))。
思路:
我们知道,Ci,j的求法有很多,这里数据范围并不大,而且模数不定,所以我们肯定要用求杨辉三角的方法来求Ci,j的。
那么对于每个k,我们预处理出来C【2000】【2000】表示Ci,j%k的值,然后我们维护一个前缀和,O(t*n)查询即可。
Ac代码:
#include<stdio.h>#include<string.h>#include<iostream>using namespace std;int c[2005][2005];int sum[2005][2005];void init(int z){ memset(sum,0,sizeof(sum)); memset(c,0,sizeof(c)); c[0][0]=1%z; c[1][0]=1%z; c[1][1]=1%z; for(int i=2;i<=2002;i++) { c[i][0]=1%z; for(int j=1;j<=i;j++) { c[i][j]=(c[i-1][j]+c[i-1][j-1])%z; } } for(int i=1;i<=2002;i++) { for(int j=1;j<=2002;j++) { int tmp=0; if(c[i][j]==0)tmp=1; sum[i][j]=sum[i][j-1]+tmp; } }}int main(){ int t; while(~scanf("%d",&t)) { while(t--) { int q,k; scanf("%d%d",&q,&k); init(k); while(q--) { int n,m; scanf("%d%d",&n,&m); int output=0; for(int i=1;i<=n;i++) { output+=sum[i][min(i,m)]; } printf("%d\n",output); } } }}
- Hrbust 2325 Astonishing Combinatorial Number【前缀和+暴力】
- Hrbust 2151 变形金刚【思维+前缀和】
- Hrbust 1742 Enclosure Plan【二维前缀和+尺取法】
- zoj 3607 Lazier Salesgirl 暴力 前缀和
- HDU 5273(暴力前缀和)
- codeforces 731F 暴力(前缀和)
- hihocoder1496-高维前缀和|暴力
- Wannafly挑战赛5 A 前缀和+暴力
- hrbust 2319 Number Game
- hrbust 1055 Single【暴力预处理】
- 【hrbust】2298 Diamond 【数学+暴力】
- Hrbust 2178 线段【暴力】水题
- Codeforces 106D Treasure Island 预处理前缀和+暴力(水
- BZOJ 1218: [HNOI2003]激光炸弹 二维前缀和,暴力
- SDUT 3254 Stars【二维前缀和+二分+暴力枚举】
- Codeforces 828B Black Square【暴力枚举+二维前缀和】
- codeforces877B(div2)Nikita and string 暴力枚举+前缀和
- Hrbust 2232 股票【暴力枚举+最大连续子序列和】水题= =
- Maven最佳实践 划分模块 配置多模块项目 pom modules
- 数值的整数次方
- 图像形态学轮廓处理&人脸边缘轮廓提取(下巴、嘴唇)
- qload 使用
- 分享一个编程学习网站——并发编程网
- Hrbust 2325 Astonishing Combinatorial Number【前缀和+暴力】
- 基于Netty的分布式 RPC 框架
- 基于DPDK的OVS安装与配置
- 调整数组顺序使奇数位于偶数前面
- 逆变、协变
- eclipse中的build和clean的作用
- Android Instrumentation初探
- Amazon S3 多部分上传
- 为什么我要用 Node.js? 案例逐一介绍