当前位置:网站首页>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 network convolution layer
- Solution: drag the Xib control to the code file, and an error setvalue:forundefined key:this class is not key value coding compliant for the key is reported
- Cmake selecting compilers and setting compiler options
- LeetCode_53(最大子数组和)
- LeetCode_ 58 (length of last word)
- How to use common datasets in pytorch
- Several methods of creating thread classes
- CF1638E. Colorful operations Kodori tree + differential tree array
- [daily question in summer] first time, second time, deal!
- 无器械健身
猜你喜欢

STM32 extended key scan

【暑期每日一题】洛谷 P5886 Hello, 2020!
![[summer daily question] Luogu p5886 Hello, 2020!](/img/ac/4be05f80aab7fb766674e6e2d16fbc.png)
[summer daily question] Luogu p5886 Hello, 2020!
![解决:Thread 1:[<*>setValue:forUndefinedKey]:this class is not key value coding-compliant for the key *](/img/88/0b99d1db2cdc70ab72d2b3c623dfaa.jpg)
解决:Thread 1:[<*>setValue:forUndefinedKey]:this class is not key value coding-compliant for the key *

LeetCode522-最长特殊序列II-哈希表-字符串-双指针

This sideline workload is small, 10-15k, free unlimited massage

Why is Internet thinking not suitable for AI products?

The design points of voice dialogue system and the importance of multi round dialogue

RuntimeError: “max_pool2d“ not implemented for ‘Long‘

分布式事务-解决方案
随机推荐
【暑期每日一题】洛谷 P1629 邮递员送信(未完待续...)
Pytest automated testing - compare robotframework framework
[hard ten treasures] - 2 [basic knowledge] characteristics of various topological structures of switching power supply
Query long transaction
Leecode question brushing record 1332 delete palindrome subsequence
Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom
Leecode record 1351 negative numbers in statistical ordered matrix
FileInputStream
分布式数据库数据一致性的原理、与技术实现方案
Technology sharing | broadcast function design in integrated dispatching
[daily question in summer] function of rogu p3742 UMI
Basic usage, principle and details of session
【暑期每日一题】洛谷 P1568 赛跑
Summary of testing experience - Testing Theory
Use and modification of prior network model
Neural network - nonlinear activation
神经网络-非线性激活
LeetCode_ 28 (implement strstr())
STM32 光敏电阻传感器&两路AD采集
How to use common datasets in pytorch