当前位置:网站首页>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;
}
边栏推荐
- LeetCode_28(实现 strStr())
- Principle, technology and implementation scheme of data consistency in distributed database
- Neural networks - use sequential to build neural networks
- Pytorch(一) —— 基本语法
- LeetCode1497-检查数组对是否可以被 k 整除-数组-哈希表-计数
- Summary of acl2021 information extraction related papers
- Research on medical knowledge atlas question answering system (I)
- 【暑期每日一题】洛谷 P2026 求一次函数解析式
- Fitness without equipment
- Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom
猜你喜欢

分布式架构系统拆分原则、需求、微服务拆分步骤

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

Introduction to JVM stack and heap

数据加载及预处理

pytorch 卷积操作
![AssertionError assert I.ndim == 4 and I.shape[1] == 3](/img/b1/0109bb0f893eb4c8915df36c100907.png)
AssertionError assert I.ndim == 4 and I.shape[1] == 3

Research on medical knowledge atlas question answering system (I)

分布式-总结列表

Neural networks - use sequential to build neural networks

The longest increasing subsequence and its optimal solution, total animal weight problem
随机推荐
C#读写应用程序配置文件App.exe.config,并在界面上显示
LeetCode_ 58 (length of last word)
【暑期每日一题】洛谷 P2026 求一次函数解析式
Leecode records the number of good segmentation of 1525 strings
Pytoch (III) -- function optimization
[daily question in summer] Luogu p1568 race
The design points of voice dialogue system and the importance of multi round dialogue
缓冲流与转换流
神经网络-使用Sequential搭建神经网络
Distributed architecture system splitting principles, requirements and microservice splitting steps
分布式全局唯一ID解决方案详解
STM32扩展版 按键扫描
常用的Transforms中的方法
数据加载及预处理
Shell之Unix运维常用命令
Neural network convolution layer
Talk about testdeploy
PR 2021 quick start tutorial, learn about the and functions of the timeline panel
对象的序列化与反序列化
C -- array