当前位置:网站首页>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;
}
边栏推荐
- Talk about testdeploy
- Pico Neo3手柄抓取物体
- 线程类的几大创建方法
- Basic skeleton of neural network nn Use of moudle
- STM32 photoresistor sensor & two channel AD acquisition
- Distributed - summary list
- Thoughts on the construction of Meizhou cell room
- C read / write application configuration file app exe. Config and display it on the interface
- Codeforces Round #771 (Div. 2) ABCD|E
- LeetCode_ 28 (implement strstr())
猜你喜欢
![[summer daily question] Luogu p5886 Hello, 2020!](/img/ac/4be05f80aab7fb766674e6e2d16fbc.png)
[summer daily question] Luogu p5886 Hello, 2020!
![AssertionError assert I.ndim == 4 and I.shape[1] == 3](/img/b1/0109bb0f893eb4c8915df36c100907.png)
AssertionError assert I.ndim == 4 and I.shape[1] == 3

神经网络-卷积层

【暑期每日一题】洛谷 P5886 Hello, 2020!

LeetCode316-去除重复字母-栈-贪心-字符串

每日一题-LeetCode1175-质数排列-数学

Basic usage, principle and details of session

C#读写应用程序配置文件App.exe.config,并在界面上显示

神经网络-最大池化的使用

Pytoch (II) -- activation function, loss function and its gradient
随机推荐
【暑期每日一题】洛谷 P2026 求一次函数解析式
Common UNIX Operation and maintenance commands of shell
Quelques outils dont les chiens scientifiques pourraient avoir besoin
Use of dataloader
Pytorch(一) —— 基本语法
[une question par jour pendant l'été] course luogu p1568
分布式全局唯一ID解决方案详解
Cmake selecting compilers and setting compiler options
STM32 extended key scan
分布式-总结列表
Common methods in transforms
分布式事务-解决方案
Neural network convolution layer
This sideline workload is small, 10-15k, free unlimited massage
手动实现一个简单的栈
[summer daily question] Luogu p5886 Hello, 2020!
C - detailed explanation of operators and summary of use cases
Construction of Meizhou nursing laboratory: equipment configuration
Pytoch (I) -- basic grammar
Matters behind the construction of paint testing laboratory