题目链接:

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.

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 modulo106 + 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 10^6 + 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

题意;

给n个砖,给定了宽c,问你有多少种墙;
这也是[1,n]的按顺序拆分成c个数的种数;也是把[1,n]放在c个盒子里(允许有空盒)的方案数; 思路: dp[n][m]=dp[n][m-1]+dp[n-1][m]+...+dp[0][m]+dp[n-1][m]+dp[n-2][m]+...+dp[1][m];
把n个相同的球放在m个盒子里(允许有空盒)的方案数为C(n+m-1,m-1);
dp[n][m]=C(n+m-1,m-1)=(n+m-1)/n*C(n+m-2,m-1)=(n+m-1)/n*dp[n-1][m];
取模的时候要快速幂求一下逆; AC代码:
#include <bits/stdc++.h>
/*
#include <vector>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio>
*/
using namespace std;
#define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<''||CH>'';F= CH=='-',CH=getchar());
for(num=;CH>=''&&CH<='';num=num*+CH-'',CH=getchar());
F && (num=-num);
}
int stk[], tp;
template<class T> inline void print(T p) {
if(!p) { puts(""); return; }
while(p) stk[++ tp] = p%, p/=;
while(tp) putchar(stk[tp--] + '');
putchar('\n');
} const LL mod=1e6+;
const double PI=acos(-1.0);
const LL inf=1e18;
const int N=5e5+;
const int maxn=;
const double eps=1e-; LL n,m,dp[N]; LL pow_mod(LL x,LL y)
{
LL s=,base=x;
while(y)
{
if(y&)s=s*base%mod;
base=base*base%mod;
y>>=;
}
return s;
} void Init()
{
dp[]=;
for(LL i=;i<=n;i++)
{
dp[i]=(dp[i-]*(i+m-)%mod)*pow_mod(i,mod-)%mod;
}
} int main()
{
read(n);read(m);
Init();
LL sum=;
for(LL i=;i<=n;i++)
{
sum=(sum+dp[i])%mod;
}
cout<<sum<<"\n"; return ;
}

codeforces 690D2 D2. The Wall (medium)(组合数学)的更多相关文章

  1. The Wall (medium)

    The Wall (medium) Heidi the Cow is aghast: cracks in the northern Wall? Zombies gathering outside, f ...

  2. Codeforces 1092 D2 Great Vova Wall (Version 2) (栈)

    题意: 给一排砖,每列的高度$a_i$,问是否可以放1*2的砖,使得n列高度一样,砖只能横着放 思路: 每两个相邻的高度相同的砖可以变成大于等于它的高度的任意高度 所以像这样的 123321 是不满足 ...

  3. Codeforces - 1081C - Colorful Bricks - 简单dp - 组合数学

    https://codeforces.com/problemset/problem/1081/C 这道题是不会的,我只会考虑 $k=0$ 和 $k=1$ 的情况. $k=0$ 就是全部同色, $k=1 ...

  4. Codeforces 1264D - Beautiful Bracket Sequence(组合数学)

    Codeforces 题面传送门 & 洛谷题面传送门 首先对于这样的题目,我们应先考虑如何计算一个括号序列 \(s\) 的权值.一件非常显然的事情是,在深度最深的.是原括号序列的子序列的括号序 ...

  5. hdu-4810 Wall Painting(组合数学)

    题目链接: Wall Painting Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  6. hdu 4810 Wall Painting (组合数学+二进制)

    题目链接 下午比赛的时候没有想出来,其实就是int型的数分为30个位,然后按照位来排列枚举. 题意:求n个数里面,取i个数异或的所有组合的和,i取1~n 分析: 将n个数拆成30位2进制,由于每个二进 ...

  7. codeforces 677C C. Vanya and Label(组合数学+快速幂)

    题目链接: C. Vanya and Label time limit per test 1 second memory limit per test 256 megabytes input stan ...

  8. codeforces D. Painting The Wall

    http://codeforces.com/problemset/problem/399/D 题意:给出n和m,表示在一个n*n的平面上有n*n个方格,其中有m块已经涂色.现在随机选中一块进行涂色(如 ...

  9. Codeforces 932 E. Team Work(组合数学)

    http://codeforces.com/contest/932/problem/E 题意:   可以看做 有n种小球,每种小球有无限个,先从中选出x种,再在这x种小球中任选k个小球的方案数 选出的 ...

随机推荐

  1. spring boot--常用配置

    spring boot 需要引用的依赖项: spring-boot-starter-parent // 所有Spring Boot组件的基础引用 spring-boot-starter-web // ...

  2. Angular Material & Hello World

    前言 Angular Material(下称Material)的组件样式至少是可以满足一般的个人开发需求(我真是毫无设计天赋),也是Angular官方推荐的组件.我们通过用这个UI库来快速实现自己的i ...

  3. codevs——2693 上学路线(施工)

    2693 上学路线(施工)  时间限制: 2 s  空间限制: 16000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 问题描述 你所在的城市街道好像一个 ...

  4. 从Java看数据结构之——树和他的操作集

    写在前面 树这种数据结构在计算机世界中有广泛的应用,比如操作系统中用到了红黑树,数据库用到了B+树,编译器中的语法树,内存管理用到了堆(本质上也是树),信息论中的哈夫曼编码等等等等.而树的实现和他的操 ...

  5. ORACLE 内部原理

    http://www.ohsdba.cn/index.php?m=Article&a=index&id=46 内部原理 2016-05-04• 如何使用BBED 2016-04-16• ...

  6. 【lombok】使用lombok注解,在代码编写过程中可以调用到get/set方法,但是在编译的时候无法通过,提示找不到get/set方法

    错误如题:使用lombok注解,在代码编写过程中可以调用到get/set方法,但是在编译的时候无法通过,提示找不到get/set方法 报错如下: 解决方法: 1.首先查看你的lombok插件是否下载安 ...

  7. windows10 開機失敗,且按F8無法進入安全模式

    windows10 開機失敗,且按F8無法進入安全模式: 在cmd視窗下: bcdedit set {default} bootmenupolicy legacy 重啟,再按F8試一試吧! To En ...

  8. Android自己主动升级框架

    先看效果 使用 package com.ydl.versionupdate; import android.app.Activity; import android.content.Context; ...

  9. CocoaPods安装问题

    主要步骤: sudo gem install cocoapods pod setup 验证是否安装成功: pod search SDWebImage 常见问题: 1 sudo gem install ...

  10. linux系列之-—03 压缩和解压缩命令

    tar命令 解包:tar zxvf FileName.tar 打包:tar czvf FileName.tar DirName gz命令 解压1:gunzip FileName.gz 解压2:gzip ...