CF692D2: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 n bricks.

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 C1 ≤ n ≤ 5000001 ≤ C ≤ 200000.

Output

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

Examples
input
5 1
output
5
input
2 2
output
5
input
3 2
output
9
input
11 5
output
4367
input
37 63
output
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

题意:n个砖块,c个格子,可以取[1,n]个砖块放到任意格子,问总的方案数。

思路:枚举砖块数i,相当于将i个球放到c个箱子的方案数。

# include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 7e5;
const LL mod = 1e6+3;
LL inv[maxn+30]={1,1}, fac[maxn+30]={1,1}, fi[maxn+30]= {1,1};
void init()
{
    for(int i=2; i<=maxn; ++i)
    {
        fac[i] = i*fac[i-1]%mod;
        inv[i] = (mod-mod/i)*inv[mod%i]%mod;
        fi[i] = fi[i-1]*inv[i]%mod;
    }
}
LL C(LL n, LL m)
{
    return fac[n]*fi[m]%mod*fi[n-m]%mod;
}
int main()
{
    init();
    LL n, c, ans=0;
    scanf("%I64d%I64d",&n,&c);
    for(LL i=1; i<=n; ++i)
    {
        ans += C(i-1+c, c-1);
        ans %= mod;
    }
    printf("%I64d\n",ans);
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值