当前位置:网站首页>求组合数 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;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- UE4 source code reading_ Bone model and animation system_ Animation node
- 796 · unlock
- Redux - learning notes
- Parameters of convolutional neural network
- 【Rust 笔记】12-闭包
- Concurrent programming (V) detailed explanation of atomic and unsafe magic classes
- 22-06-28 西安 redis(02) 持久化机制、入门使用、事务控制、主从复制机制
- Simple demo of solving BP neural network by gradient descent method
- 【Rust 笔记】07-结构体
- Chocolate installation
猜你喜欢
随机推荐
Unity editor expansion - controls, layouts
Constraintlayout's constraintset dynamically modifies constraints
Explain sizeof, strlen, pointer, array and other combination questions in detail
Message pack in C deserializes array objects
Pit & ADB wireless debugging of vivo real machine debugging
Facial expression recognition based on pytorch convolution -- graduation project
ES6 promise learning notes
[concurrent programming] explicit lock and AQS
【Rust笔记】02-所有权
【Rust笔记】05-错误处理
分配异常的servlet
Solution of 300ms delay of mobile phone
【Rust笔记】06-包和模块
Message queue for interprocess communication
Notes and bugs generated during the use of h:i:s and y-m-d
[concurrent programming] collaboration between threads
[rust note] 10 operator overloading
Notes on understanding applets 2022/7/3
Campus lost and found platform based on SSM, source code, database script, project import and operation video tutorial, Thesis Writing Tutorial
Servlet的生命周期