The Wall (medium)

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 106 + 3.

Examples
input
  1. 5 1
output
  1. 5
input
  1. 2 2
output
  1. 5
input
  1. 3 2
output
  1. 9
input
  1. 11 5
output
  1. 4367
input
  1. 37 63
output
  1. 230574
Note

The number 106 + 3 is prime.

In the second sample case, the five walls are:

  1. 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:

  1. B B
    B B B B
    B., .B, BB, and BB
    分析:球盒模型(隔板法)+乘法逆元;注意爆int
    代码:
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <climits>
  7. #include <cstring>
  8. #include <string>
  9. #include <set>
  10. #include <map>
  11. #include <queue>
  12. #include <stack>
  13. #include <vector>
  14. #include <list>
  15. #include <ext/rope>
  16. #define rep(i,m,n) for(i=m;i<=n;i++)
  17. #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
  18. #define vi vector<int>
  19. #define pii pair<int,int>
  20. #define inf 0x3f3f3f3f
  21. #define pb push_back
  22. #define mp make_pair
  23. #define fi first
  24. #define se second
  25. #define ll long long
  26. #define pi acos(-1.0)
  27. const int maxn=7e5+;
  28. const int mod=1e6+;
  29. const int dis[][]={{,},{-,},{,-},{,}};
  30. using namespace std;
  31. using namespace __gnu_cxx;
  32. ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
  33. ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p%mod;p=p*p%mod;q>>=;}return f;}
  34. int n,m,ans,fac[maxn]={};
  35. void init()
  36. {
  37. for(int i=;i<=maxn-;i++)fac[i]=1ll*i*fac[i-]%mod;
  38. }
  39. int inv(int p)
  40. {
  41. return qpow(p,mod-);
  42. }
  43. int C(int x,int y)
  44. {
  45. return 1ll*fac[x]*inv(fac[y])%mod*inv(fac[x-y])%mod;
  46. }
  47. int main()
  48. {
  49. int i,j,k,t;
  50. scanf("%d%d",&n,&m);
  51. init();
  52. rep(i,m,n+m-)ans=(ans+C(i,m-))%mod;
  53. printf("%d\n",ans);
  54. //system ("pause");
  55. return ;
  56. }

The Wall (medium)的更多相关文章

  1. codeforces 690D2 D2. The Wall (medium)(组合数学)

    题目链接: D2. The Wall (medium) time limit per test 2 seconds memory limit per test 256 megabytes input ...

  2. Swift LeetCode 目录 | Catalog

    请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift    说明:题目中含有$符号则为付费题目. 如 ...

  3. All LeetCode Questions List 题目汇总

    All LeetCode Questions List(Part of Answers, still updating) 题目汇总及部分答案(持续更新中) Leetcode problems clas ...

  4. [poj1113][Wall] (水平序+graham算法 求凸包)

    Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...

  5. gcc -Wall -pedantic -ansi(转载)

    转载自R-G-Y-CQ的新浪博客 -Wall显示所有的警告信息 -Wall选项可以打开所有类型的语法警告,以便于确定程序源代码是否是正确的,并且尽可能实现可移植性. 对Linux开发人员来讲,GCC给 ...

  6. UVALive 2453 Wall (凸包)

    题意:给你一个多边形的城堡(多个点),使用最短周长的城墙将这个城堡围起来并保证城墙的每个点到城堡上的每个点的距离都不小于l 题解:因为两点间的直线一定比折线短,所以这样做 先使用所有点求得一个凸包,接 ...

  7. write/wall 1

    linux:/opt/software/lktest/c # wallhellllllllllllllllllllooooooooooooooooo^[[AasZZZZZZ^Clinux:/opt/s ...

  8. Image Wall - jQuery & CSS3 图片墙效果

    今天我们要为您展示如何基于 jQuery 和 CSS3 创建一个整洁的图片墙效果.我们的想法是在页面上洒上一些大小不同的缩略图,并在当我们点击图片时候显示丝带,会显示一些描述,再次点击缩略图时,丝带将 ...

  9. Jenkins项目构建结果通知Email的替代方案Wall Display插件

    插件:https://wiki.jenkins-ci.org/display/JENKINS/Wall+Display+Plugin 效果: 操作: 直接在一个大屏幕上打开这个项目的构建页面,那么每次 ...

随机推荐

  1. android 布局页面文件出错故障排除Exception raised during rendering: java.lang.System.arraycopy([CI[CII)V

    今天在看布局文件的时候出现 android 布局页面文件出错故障排除Exception raised during rendering: java.lang.System.arraycopy([CI[ ...

  2. hdu_5791_Two(DP)

    题目链接:hdu_5791_Two 题意: 给你两串数列,问你相同的子序列有多少个,要注意,可以重复,比如1 和1 1 1 ,相同的子序列为3个 题解: 就和求最长公共子序列差不多,只不过要全部加起来 ...

  3. ADT(abstract data types)抽象数据类型

    1.What is it? An abstract data type is a set of objects together with a set of operations. 抽象数据类型是带有 ...

  4. 分布式事务实现-Spanner

    Spanner要满足的external consistency 是指:后开始的事务一定可以看到先提交的事务的修改.所有事务的读写都加锁可以解决这个问题,缺点是性能较差.特别是对于一些workload中 ...

  5. log4j之mybatis配置

    简单记录一下,配置,因为项目要转向maven架构,所以jar有maven管理,配置完成之后发现原先的sql语句都出不来了,于是搜了一下 mybatis+log4j所需要的依赖如下(我列出我用的版本): ...

  6. hover带有动画效果的导航

    html,body{overflow-x:hidden;} ul,li{list-style: none;} .nav{width:100%; height: 26px; overflow: hidd ...

  7. sqlserver日志文件过大的处理方法

      SqlServer 数据库中与备份和恢复相关的日志文件有MDF和LDF文件 存在于\\sqlserver_install_dir\MSSQL\Data\1.文件解释.mdf文件    MDF是SQ ...

  8. html屏蔽右键、禁止复制与禁止查看源代码

    <script> function doNothing(){ window.event.returnValue=false; return false; } </script> ...

  9. “strcmp()” Anyone?

    “strcmp()” Anyone? strcmp() is a library function in C/C++ which compares two strings. It takes two ...

  10. WPF Template模版之寻找失落的控件【三】

    “井水不犯河水”常用来形容两个组织之间界限分明.互不相干,LogicTree与控件内部这颗小树之间就保持着这种关系.换句话说,如果UI元素树上有个X:Name=“TextBox1”的控件,某个控件内部 ...