当前位置:网站首页>求组合数 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;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- 100 GIS practical application cases (78) - Multi compliance database design and data warehousing
- 数据库原理期末复习
- Unity Editor Extension - event handling
- Binary to decimal, decimal to binary
- OpenGL learning notes
- php public private protected
- 【Rust 笔记】07-结构体
- Deep parsing (picture and text) JVM garbage collector (II)
- 【Rust笔记】02-所有权
- [rust notes] 12 closure
猜你喜欢

Markdown learning

Vscode, idea, VIM development tool shortcut keys

DOM 渲染系统(render mount patch)响应式系统

Chocolate installation

Query XML documents with XPath

二进制转十进制,十进制转二进制

Deeply understand the underlying data structure of MySQL index

I made mistakes that junior programmers all over the world would make, and I also made mistakes that I shouldn't have made
![[rust notes] 02 ownership](/img/f7/74f8ea3bd697957f9ebfa3e1513fda.png)
[rust notes] 02 ownership

22-06-28 Xi'an redis (02) persistence mechanism, entry, transaction control, master-slave replication mechanism
随机推荐
Development material set
Gradle's method of dynamically modifying APK package name
树形DP AcWing 285. 没有上司的舞会
Dom4j traverses and updates XML
Monotonic stack -503 Next bigger Element II
Common DOS commands
[concurrent programming] thread foundation and sharing between threads
UE4 source code reading_ Mobile synchronization
Notes and bugs generated during the use of h:i:s and y-m-d
【Rust 笔记】07-结构体
[rust notes] 09- special types and generics
分配异常的servlet
【Rust 笔记】10-操作符重载
数据库原理期末复习
22-05-26 Xi'an interview question (01) preparation
How to use Jupiter notebook
UE4 source code reading_ Bone model and animation system_ Animation node
Message pack in C deserializes array objects
PHP mnemonic code full text 400 words to extract the first letter of each Chinese character
【Rust 笔记】12-闭包