题目链接:

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<'0'||CH>'9';F= CH=='-',CH=getchar());for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {if(!p) { puts("0"); return; }while(p) stk[++ tp] = p%10, p/=10;while(tp) putchar(stk[tp--] + '0');putchar('\n');
}const LL mod=1e6+3;
const double PI=acos(-1.0);
const LL inf=1e18;
const int N=5e5+10;
const int maxn=1005;
const double eps=1e-10;LL n,m,dp[N];LL pow_mod(LL x,LL y)
{LL s=1,base=x;while(y){if(y&1)s=s*base%mod;base=base*base%mod;y>>=1;}return s;
}void Init()
{dp[0]=1;for(LL i=1;i<=n;i++){dp[i]=(dp[i-1]*(i+m-1)%mod)*pow_mod(i,mod-2)%mod;}
}int main()
{read(n);read(m);Init();LL sum=0;for(LL i=1;i<=n;i++){sum=(sum+dp[i])%mod;}cout<<sum<<"\n";return 0;
}

转载于:https://www.cnblogs.com/zhangchengc919/p/5661874.html

codeforces 690D2 D2. The Wall (medium)(组合数学)相关推荐

  1. CodeForces - 560E Gerald and Giant Chess(组合数学+dp)

    题目链接:点击查看 题目大意:给出一个 n∗mn*mn∗m 的矩阵,其中有 kkk 个坏点,每次只能向右走或向下走,问从点 (1,1)(1,1)(1,1) 到点 (n,m)(n,m)(n,m) 共有多 ...

  2. Codeforces Gym 100338H High Speed Trains 组合数学+dp+高精度

    原题链接:http://codeforces.com/gym/100338/attachments/download/2136/20062007-winter-petrozavodsk-camp-an ...

  3. CodeForces - 1284C New Year and Permutation(组合数学+思维)

    题目链接:点击查看 题目大意:首先定义名词"排列"的意思是,一段数列中的数字升序排序后可以组成连续的一段数列,换句话说,满足一段区间内的最大值-最小值=r-l则称这个区间的数列为& ...

  4. CF思维联系–CodeForces - 223 C Partial Sums(组合数学的先线性递推)

    ACM思维题训练集合 You've got an array a, consisting of n integers. The array elements are indexed from 1 to ...

  5. Codeforces 1342E Placing Rooks(容斥+组合数学)

    题目链接:E. Placing Rooks 题意:给定一个N*棋盘,要求摆放n个rooks(国际象棋里能横竖走的那啥),使得每个格子都能被rooks攻击到,并且正好有k对rooks能相互攻击到,求有多 ...

  6. codeforces 869C The Intriguing Obsession【组合数学+dp+第二类斯特林公式】

    C. The Intriguing Obsession time limit per test 1 second memory limit per test 256 megabytes input s ...

  7. Codeforces 1546 D. AquaMoon and Chess —— 组合数学,一点点想法

    This way 题意: 给你一个01串s,你每次可以做一个操作如果s[i]=1: 1.如果i+2<=n且s[i+2]=0且s[i+1]=1,那么可以将s[i]的1移到s[i+2] 2.如果i- ...

  8. CodeForces 215 E.Periodical Numbers(组合数学+dp)

    Description 给出一个区间[L,R][L,R],问这个区间中有多少数字的二进制表示是有循环节的 Input 两个正整数L,RL,R(1≤L≤R≤1018)(1\le L\le R\le 10 ...

  9. LSNU寒假集训 题解

    目录 LSNU寒假第一场(基础算法+几何) A - Fifa and Fafa B - Anton and Lines C - Minimum path D - Thematic Contests E ...

  10. 输入法按照选字频率排序的C语言程序算法,算法与数据结构之选择排序(C语言)...

    #include #include void SelectSort(int *a,int n);//预声明要调用的函数 int main(void) { int k; int x[]={,,,,,,, ...

最新文章

  1. 【数据结构】回顾散列表
  2. 访问IIS元数据库失败解决方法(转)
  3. windows无法远程
  4. 初学 Delphi 嵌入汇编[10] - 函数返回值与寄存器
  5. oracle ebs 采购订单 为员工分配职务,oracle—EBS-采购功能点操作手册
  6. C++_类和对象_C++多态_案例3-电脑组装---C++语言工作笔记075
  7. ERP流程的一个生动的例子:
  8. 区块链 用户身份权限模式 方案
  9. golang 判断map的键key是否存在
  10. [网络安全自学篇] 九十三.《Windows黑客编程技术详解》之木马开机自启动技术(注册表、计划任务、系统服务)
  11. windows驱动加载顺序
  12. 11个好用的黑科技资源搜索网站
  13. 基于ELMO Composer的MAXON RE40电机增益调节
  14. 网线断了也能上网?被限速?
  15. 化工厂定位系统健全企业安全体系
  16. 电脑连接宽带,给手机开热点
  17. 工业大数据技术与应用2017材料整理
  18. ALLEGRO 中导入PADS的asc文件时显示pads_in.log does not exit
  19. 雨听|在wps中将某一页ppt导出为图片
  20. Excel VBA语句集300

热门文章

  1. android activity 的四种启动模式
  2. 处理 Exception 的几种实践,很优雅,已被很多团队采纳!
  3. yyds!Java 性能优化的 50 个细节(珍藏版)
  4. 2021年2月移动互联网全行业排行榜
  5. 我敢说,你的登录接口肯定不安全
  6. 2020 年 9 月程序员工资统计,新出炉!
  7. 举世闻名的 SQL 注入是什么?这个漫画告诉你!
  8. Spring Boot ES 实战,直接拿来用!
  9. CodeReview 常见代码问题( 上 )
  10. 不知道这十项Linux常识,就别说自己玩过Linux!