当前位置:网站首页>求组合数 AcWing 885. 求组合数 I
求组合数 AcWing 885. 求组合数 I
2022-07-03 08:41:00 【T_Y_F666】
求组合数 AcWing 885. 求组合数 I
原题链接
算法标签
组合数学 组合计数 递推
思路

代码
#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>=b;--i)
using namespace std;
const int N = 2005, mod = 1e9+7;
int c[N][N];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
void init(){
rep(i, 0, N){
rep(j, 0, i+1){
// 从i中选取0个 方案数为1
if(!j){
c[i][j]=1;
}else{
c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
}
}
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n=read();
init();
while(n--){
int a=read(), b=read();
printf("%lld\n", c[a][b]);
}
return 0;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
猜你喜欢

MySQL 8

基于SSM的校园失物招领平台,源码,数据库脚本,项目导入运行视频教程,论文撰写教程

单调栈-503. 下一个更大元素 II

22-06-27 西安 redis(01) 安装redis、redis5种常见数据类型的命令

Final review of Database Principles

记忆化搜索 AcWing 901. 滑雪

SQL statement error of common bug caused by Excel cell content that is not paid attention to for a long time

Deep parsing JVM memory model

Alibaba canal actual combat

Monotonic stack -42 Connect rainwater
随机推荐
How to use Jupiter notebook
100 GIS practical application cases (78) - Multi compliance database design and data warehousing
First Servlet
Redis cluster series 4
How to delete CSDN after sending a wrong blog? How to operate quickly
数据库原理期末复习
Osganimation library parsing
Eating fruit
树形DP AcWing 285. 没有上司的舞会
[rust notes] 09- special types and generics
On the difference and connection between find and select in TP5 framework
Alibaba canaladmin deployment and canal cluster Ha Construction
createjs easeljs
Graphics_ Learnopongl learning notes
高斯消元 AcWing 883. 高斯消元解线性方程组
Find the intersection of line segments
Concurrent programming (V) detailed explanation of atomic and unsafe magic classes
MySQL 8
[concurrent programming] explicit lock and AQS
Mortgage Calculator