题目链接:

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. ubuntu下U盘变为只读

    原文地址:http://www.cnblogs.com/coding-way/p/4243331.html 首先执行命令: tail -f /var/log/syslog 然后插入有问题的U盘,tai ...

  2. mysql获取子父级节点

    获取所有子节点 DROP FUNCTION IF EXISTS `F_Co29_GetAllChildrenIdsOfTaskevent`;DELIMITER //CREATE FUNCTION `F ...

  3. github/gitlab ssh-keys全局唯一

    我们知道,通过在gitlab.github上设置ssh-key,可以直接拉取代码:git clone …… 公司为了代码安全,会对代码访问权限进行控制,不同人有不同代码的访问权限. 有时候,为了临时获 ...

  4. Nuxt.js使用lazyload

    Vue的使用方式: 1. 安装插件: npm install vue-lazyload --save-dev 2. main.js引入插件: import VueLazyLoad from 'vue- ...

  5. 用户空间&内核空间学习 & top命令 & time命令

    参考了这篇文章 http://www.ruanyifeng.com/blog/2016/12/user_space_vs_kernel_space.html 简单说,Kernel space 是 Li ...

  6. CentOS 6.x安装多GCC版本号,cmake的安装与使用

    操作系统:CentOS release 6.5 (Final) 当前gcc版本号:build=x86_64-redhat-linux                           Thread ...

  7. BUPT复试专题—日期(2013)

    题目描述 请你计算出第年月日是第X年的第几天.其中,1月1日是第一天,1月2日是第二天,以此类推. 计算时请注意闰年的影响.对于非整百年,年数能整除4是闰年,否则不是闰年:对于整百年,年数能整除400 ...

  8. C#总结复习5(需要进一步复习)

    第十五章 接口 1.接口: C++中允许多继承没有接口的概念.而java与C#中有,因为C#中 是单继承多接口. 所谓的接口,其实和抽象类.方法相似.都只有一个空方法.其本身不可以为基类,但是允许被其 ...

  9. Java学习之基本概念

    1.java体系结构: j2se:是Java的标准版,用于标准的应用开. j2ee:是Java的企业版,用于企业级的应用服务,web服务开发. j2me:是Java的微型版,用户手机或嵌入式开发. p ...

  10. ActiveMQ(六) 转

    package pfs.y2017.m11.mq.activemq.demo07; import org.apache.activemq.ActiveMQConnectionFactory; impo ...