CodeForces - 690D2 The Wall (medium)(还是组合数)

D2. The Wall (medium)

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Heidi the Cow is aghast: cracks in the northern Wall? Zombies gathering outside, forming groups, preparing their assault? This must not happen! Quickly, she fetches her HC2 (Handbook of Crazy Constructions) and looks for the right chapter:

How to build a wall:

  1. Take a set of bricks.
  2. Select one of the possible wall designs. Computing the number of possible designs is left as an exercise to the reader.
  3. Place bricks on top of each other, according to the chosen design.

This seems easy enough. But Heidi is a Coding Cow, not a Constructing Cow. Her mind keeps coming back to point 2b. Despite the imminent danger of a zombie onslaught, she wonders just how many possible walls she could build with up to nbricks.

A wall is a set of wall segments as defined in the easy version. How many different walls can be constructed such that the wall consists of at least 1 and at most n bricks? Two walls are different if there exist a column c and a row r such that one wall has a brick in this spot, and the other does not.

Along with n, you will be given C, the width of the wall (as defined in the easy version). Return the number of different walls modulo 106 + 3.

Input

The first line contains two space-separated integers n and C, 1 ≤ n ≤ 500000, 1 ≤ C ≤ 200000.

Output

Print the number of different walls that Heidi could build, modulo 106 + 3.

Examples

input

Copy

5 1

output

Copy

5

input

Copy

2 2

output

Copy

5

input

Copy

3 2

output

Copy

9

input

Copy

11 5

output

Copy

4367

input

Copy

37 63

output

Copy

230574

Note

The number 106 + 3 is prime.

In the second sample case, the five walls are:

            B        B
B., .B, BB, B., and .B

In the third sample case, the nine walls are the five as in the second sample case and in addition the following four:

B    B
B    B  B        B
B., .B, BB, and BB

 

规律是:C(n+c,min(n,c))-1;

(找规律的过程省略,因为根本没有找到规律,只知道a[n][m]=a[m][n]=a[m][n-1]+a[m-1][n]+1)

 

这个是用卢卡斯加逆元求组合数:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;

const int p = 1e6+3;

/*ll quick_mod(ll a,ll b){//这个也是快速幂求逆元
    ll ans = 1;
    a %= p;
    while(b){
        if(b&1){
            ans = ans*a%p;
            b--;
        }
        b >>= 1;
        a = a*a%p;
    }
    return ans;
}*/

ll quick_mod(ll a ,ll b){//快速幂求逆元
    if(b==0) return 1;
    ll res = quick_mod(a*a%p,b/2);
    if(b%2)
        res = res*a%p;
    return res;
}

ll C(ll n,ll m){//求组合数C(m,n)
    if(m>n) return 0;
    ll ans = 1;
    for(ll i=1;i<=m;i++){
        ll a=(n-m+i)%p;
        ll b = i%p;
        ans = ans*(a*quick_mod(b,p-2)%p)%p;
    }
    return ans;
}

ll Lucas(ll n,ll m){//卢卡斯定理
    return m==0?1:(C(n%p,m%p)*Lucas(n/p,m/p)%p);
}

int main()
{
    int n,c;
    while(cin >> n >> c){
        cout << Lucas(n+c,min(n,c))-1<<endl;
    }
    return 0;
}

 

这个题的数据比较小,所以也可以直接用阶乘和逆元求:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;

const int p = 1e6+3;

/*ll quick_mod(ll a,ll b){//这个也是快速幂求逆元
    ll ans = 1;
    a %= p;
    while(b){
        if(b&1){
            ans = ans*a%p;
            b--;
        }
        b >>= 1;
        a = a*a%p;
    }
    return ans;
}*/

ll quick_mod(ll a ,ll b){//快速幂求逆元
    if(b==0) return 1;
    ll res = quick_mod(a*a%p,b/2);
    if(b%2)
        res = res*a%p;
    return res;
}

int main()
{
    int n,c;
    while(cin >> n >> c){
        int i;
        ll ans=1;
        for(int i = 1;i <= min(n,c);i++){
            ans = (ans%p*(n+c+i-min(n,c))%p*quick_mod(i,p-2)%p)%p;
        }
        cout <<ans-1 <<endl;
    }
    return 0;
}

 

内容概要:本文详细介绍了施耐德M580系列PLC的存储结构、系统硬件架构、上电写入程序及CPU冗余特性。在存储结构方面,涵盖拓扑寻址、Device DDT远程寻址以及寄存器寻址三种方式,详细解释了不同类型的寻址方法及其应用场景。系统硬件架构部分,阐述了最小系统的构建要素,包括CPU、机架和模块的选择与配置,并介绍了常见的系统拓扑结构,如简单的机架间拓扑和远程子站以太网菊花链等。上电写入程序环节,说明了通过USB和以太网两种接口进行程序下载的具体步骤,特别是针对初次下载时IP地址的设置方法。最后,CPU冗余部分重点描述了热备功能的实现机制,包括IP通讯地址配置和热备拓扑结构。 适合人群:从事工业自动化领域工作的技术人员,特别是对PLC编程及系统集成有一定了解的工程师。 使用场景及目标:①帮助工程师理解施耐德M580系列PLC的寻址机制,以便更好地进行模块配置和编程;②指导工程师完成最小系统的搭建,优化系统拓扑结构的设计;③提供详细的上电写入程序指南,确保程序下载顺利进行;④解释CPU冗余的实现方式,提高系统的稳定性和可靠性。 其他说明:文中还涉及一些特殊模块的功能介绍,如定时器事件和Modbus串口通讯模块,这些内容有助于用户深入了解M580系列PLC的高级应用。此外,附录部分提供了远程子站和热备冗余系统的实物图片,便于用户直观理解相关概念。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值