当前位置:网站首页>AcWing 885. Find the combination number I (recursive preprocessing)
AcWing 885. Find the combination number I (recursive preprocessing)
2022-07-01 04:51:00 【MangataTS】
Problem plane connection
https://www.acwing.com/problem/content/887/
Ideas
Through the knowledge of combinatorial mathematics, we can know C a b = C a − 1 b + C a − 1 b − 1 C_a^b = C_{a-1}^b + C_{a-1}^{b-1} Cab=Ca−1b+Ca−1b−1 Of , The right side of the equation is from a − 1 a-1 a−1 Choose from the number of b − 1 b-1 b−1 Number and from a − 1 a-1 a−1 Choose from the number of b b b Number of cases , Corresponding to the current b b b Number of options and no options ( It seems to be a little similar to the idea of backpack ), Then we can get the result by recursion 2000 All combinations within , See code for details
Code
#include<bits/stdc++.h>
using namespace std;
//---------------- Custom part ----------------
#define ll long long
#define mod 1000000007
#define endl "\n"
#define PII pair<int,int>
#define INF 0x3f3f3f3f
int dx[4] = {
-1, 0, 1, 0}, dy[4] = {
0, 1, 0, -1};
ll ksm(ll a,ll b) {
ll ans = 1;
for(;b;b>>=1LL) {
if(b & 1) ans = ans * a % mod;
a = a * a % mod;
}
return ans;
}
ll lowbit(ll x){
return -x & x;}
const int N = 2e3+10;
//---------------- Custom part ----------------
ll t,n,m,q,c[N][N];
void init(){
for(int i = 0;i < N; ++i) c[i][0] = 1;// Initialization selection 0 The situation of
for(int i = 1;i < N; ++i) {
for(int j = 1;j <= i; ++j) {
c[i][j] = (c[i-1][j] + c[i-1][j-1]) % mod;
}
}
}
void slove(){
ll a,b;
cin>>a>>b;
cout<<c[a][b]<<endl;
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
init();
cin>>t;
while(t--){
slove();
}
return 0;
}
边栏推荐
- Neural networks - use of maximum pooling
- 最长递增子序列及最优解、动物总重量问题
- Neural networks - use sequential to build neural networks
- STM32 光敏电阻传感器&两路AD采集
- Introduction to JVM stack and heap
- This sideline workload is small, 10-15k, free unlimited massage
- Pytoch (II) -- activation function, loss function and its gradient
- Dede collection plug-in does not need to write rules
- Some tools that research dogs may need
- Basic usage, principle and details of session
猜你喜欢

Neural networks - use of maximum pooling

解决:拖动xib控件到代码文件中,报错setValue:forUndefinedKey:this class is not key value coding-compliant for the key

分布式全局唯一ID解决方案详解

Use of dataloader

Pytoch (II) -- activation function, loss function and its gradient

数据加载及预处理

Openresty rewrites the location of 302
![AssertionError assert I.ndim == 4 and I.shape[1] == 3](/img/b1/0109bb0f893eb4c8915df36c100907.png)
AssertionError assert I.ndim == 4 and I.shape[1] == 3

Distributed - summary list

Pytoch (I) -- basic grammar
随机推荐
Shell analysis server log command collection
科研狗可能需要的一些工具
STM32扩展板 温度传感器和温湿度传感器的使用
Buffer stream and transform stream
Fitness without equipment
Some tools that research dogs may need
【暑期每日一题】洛谷 P5740【深基7.例9】最厉害的学生
Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom
[hardware ten treasures catalogue] - reprinted from "hardware 100000 whys" (under continuous update ~ ~)
缓冲流与转换流
科研狗可能需要的一些工具
Pytorch(二) —— 激活函数、损失函数及其梯度
Use of dataloader
Distributed - summary list
Codeworks round 449 (Div. 1) C. Kodori tree template
Dataloader的使用
【硬十宝典】——2.【基础知识】开关电源各种拓扑结构的特点
LeetCode522-最长特殊序列II-哈希表-字符串-双指针
【FTP】FTP常用命令,持续更新中……
Matters behind the construction of paint testing laboratory