当前位置:网站首页>AcWing 889. 01 sequence satisfying the condition (Cartland number)
AcWing 889. 01 sequence satisfying the condition (Cartland number)
2022-07-01 04:51:00 【MangataTS】
Topic linking
https://www.acwing.com/problem/content/891/
Ideas
Because there is n individual 1 and n individual 0, Then we can finally reach the point (n,n), It's hard for us to think positively , So we can see in the middle 1 The quantity ratio of 0 In many cases , For this method, we can turn it into a plane diagram ,1 It means taking a step to the right ,0 It means taking a step up , Then the opposite of what we are asking for now is to go through y = x + 1 y=x+1 y=x+1 The number of schemes for this line , We can do to this line (n,n) A symmetric graph of the is (n-1,n+1), We will find that the number of schemes in this position is : C 2 n n − 1 C_{2n}^{n-1} C2nn−1, For walking to (n,n) The number of all schemes is : C 2 n n C_{2n}^{n} C2nn, Then let's just make a difference , After simplification is :
C 2 n n n + 1 \frac{C_{2n}^{n}}{n+1} n+1C2nn This number is also known as the Cartland number
Code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
ll ksm(ll a,ll b){
ll res = 1;
for(;b;b>>=1,a=a*a%mod) if(b & 1) res = res * a % mod;
return res;
}
ll C(ll a,ll b){
b = min(a-b,b);
ll ansL = 1,ansR = 1;
for(int i = 1;i <= b; ++i){
ansL = ansL * (a-i+1) % mod;
ansR = ansR * i % mod;
}
ll ans = ansL * ksm(ansR,mod-2) % mod;
return ans;
}
ll slove(ll n){
return (C(2*n,n)-C(2*n,n-1) + mod) % mod;
}
int main()
{
ll a;
scanf("%lld",&a);
printf("%lld\n",slove(a));
return 0;
}
边栏推荐
- [une question par jour pendant l'été] course luogu p1568
- Difficulties in the development of knowledge map & the importance of building industry knowledge map
- Matters behind the construction of paint testing laboratory
- 1076 Forwards on Weibo
- LeetCode_ 28 (implement strstr())
- Implementation of distributed lock
- STM32扩展版 按键扫描
- Several methods of creating thread classes
- 分布式数据库数据一致性的原理、与技术实现方案
- 分布式锁的实现
猜你喜欢

Difficulties in the development of knowledge map & the importance of building industry knowledge map

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

Pytorch(二) —— 激活函数、损失函数及其梯度

Distributed architecture system splitting principles, requirements and microservice splitting steps

Distributed - summary list

Common methods in transforms

数据加载及预处理

Why is Internet thinking not suitable for AI products?

LeetCode1497-检查数组对是否可以被 k 整除-数组-哈希表-计数

Fitness without equipment
随机推荐
分布式锁的实现
How do I sort a list of strings in dart- How can I sort a list of strings in Dart?
pytorch中常用数据集的使用方法
【FTP】FTP连接时出现“227 Entering Passive Mode”的解决方法
神经网络-卷积层
Pytorch(二) —— 激活函数、损失函数及其梯度
LeetCode_66(加一)
Neural network - nonlinear activation
STM32 光敏电阻传感器&两路AD采集
线程类的几大创建方法
神经网络的基本骨架-nn.Moudle的使用
Design experience of Meizhou clinical laboratory
STM32 photoresistor sensor & two channel AD acquisition
Distributed architecture system splitting principles, requirements and microservice splitting steps
Some tools that research dogs may need
分布式架构系统拆分原则、需求、微服务拆分步骤
数据加载及预处理
[summer daily question] Luogu p5886 Hello, 2020!
C - detailed explanation of operators and summary of use cases
Pytorch(三) —— 函数优化