链接:

https://vjudge.net/problem/LightOJ-1102

题意:

As I am fond of making easier problems, I discovered a problem. Actually, the problem is 'how can you make n by adding k non-negative integers?' I think a small example will make things clear. Suppose n=4 and k=3. There are 15 solutions. They are

  1.  0 0 4
  2.  0 1 3
  3.  0 2 2
  4.  0 3 1
  5.  0 4 0
  6.  1 0 3
  7.  1 1 2
  8.  1 2 1
  9.  1 3 0
  10. 2 0 2

  11. 2 1 1

  12. 2 2 0

  13. 3 0 1

  14. 3 1 0

  15. 4 0 0

As I have already told you that I use to make problems easier, so, you don't have to find the actual result. You should report the result modulo 1000,000,007.

思路:

转化为将n个物体分成k快,要插k-1个板,但是因为可以分出0个物体,所以我们加上k,保证每个部分必须有一个,答案就是C(n+k-1, k-1)

使用卢卡斯定理和逆元

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MOD = 1e9+7;
const int MAXN = 1e6+10; int Fac[MAXN*2];
int n, k; void GetFac()
{
Fac[0] = Fac[1] = 1;
for (int i = 2;i < MAXN*2+10;i++)
Fac[i] = (1LL*Fac[i-1]*i)%MOD;
} LL PowMod(LL a, LL b, LL p)
{
LL res = 1;
while(b)
{
if (b&1)
res = res*a%p;
a = a*a%p;
b >>= 1;
}
return res;
} LL C(LL n, LL m, LL p)
{
if (n == m)
return 1;
if (n < m)
return 0;
return (1LL*Fac[n]*PowMod(1LL*Fac[m]*Fac[n-m]%p, p-2, p))%p;
} LL Lucas(LL n, LL m, LL p)
{
if (m == 0)
return 1;
return (C(n%p, m%p, p)*Lucas(n/p, m/p, p))%p;
} int main()
{
// freopen("test.in", "r", stdin);
GetFac();
int t, cnt = 0;
scanf("%d", &t);
while (t--)
{
printf("Case %d:", ++cnt);
scanf("%d%d", &n, &k);
printf(" %lld\n", Lucas(n+k-1, k-1, MOD));
} return 0;
}

LightOJ - 1102 - Problem Makes Problem(组合数)的更多相关文章

  1. (light oj 1102) Problem Makes Problem (组合数 + 乘法逆元)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1102 As I am fond of making easier problems, ...

  2. lightoj 1102 - Problem Makes Problem

    1102 - Problem Makes Problem As I am fond of making easier problems, I discovered a problem. Actuall ...

  3. Lightoj 1004 - Monkey Banana Problem

    题目链接:http://acm.hust.edu.cn/vjudge/contest/121396#problem/F http://lightoj.com/volume_showproblem.ph ...

  4. light oj 1102 - Problem Makes Problem组合数学(隔板法)

    1102 - Problem Makes Problem As I am fond of making easier problems, I discovered a problem. Actuall ...

  5. lightoj 1060 - nth Permutation(组合数+贪心)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1060 题解:如果是不重复数的这些操作可以用康托展开的逆来求,如果是有重复数字出 ...

  6. lightoj 1134 - Be Efficient(组合数)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1134 题解:简单的一道组合题,现求一下前缀和,然后只要找前缀和膜m的结果相同的 ...

  7. CodeForces 689E Mike and Geometry Problem (离散化+组合数)

    Mike and Geometry Problem 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/I Description M ...

  8. 不可解问题之停机问题(Undecidable Problem Halting Problem)

    计算机技术已运用到人类生活的方方面面,帮助人类解决各种问题.可你是否有想过,计算机是否能为人类解决所有问题呢? 假如你是一个程序猿,你已编写过很多程序.有些程序一下子就能出结果,有些程序则好久都没有显 ...

  9. LightOJ 1070 - Algebraic Problem 推导+矩阵快速幂

    http://www.lightoj.com/volume_showproblem.php?problem=1070 思路:\({(a+b)}^n =(a+b){(a+b)}^{n-1} \) \(( ...

随机推荐

  1. js玩命加载……

    在请求数据加载的过程中,经常需要显示请求等待,写了一个简单的请求等待—- html代码如下 <!--页面载入显示--> <div id="dataLoad" st ...

  2. MySQL数据库去重 SQL解决

    MySQL数据库去重的方法 ​ 数据库最近有很多重复的数据,数据量还有点大,本想着用代码解决,后来发现用SQL就能解决,这里记录一下 看这条SQL DELETE consum_record FROM ...

  3. c++连接打印机(转载)

    Visual C++6.0是开发Windows应用程序的强大工具,但是要通过它实现程序的打印功能,一直是初学者的一个难点,经常有朋友询问如何在VC中实现打印功能,他们往往感到在MFC提供的框架内实现这 ...

  4. vue中指令绑定的v-if逻辑结构

    <!-- if判断 --> <div id="app2"> <p v-if="seen"> <!-- 给p标签绑定指令 ...

  5. laravel中一些非常常用的php artisan命令

    php artisan 命令在开发laravel项目中非常常用,下面是一些总结 composer config -g repo.packagist composer https://mirrors.a ...

  6. scope:provided影响子依赖

    一.问题 在上一篇<SpringBoot项目启动不走内嵌容器>中发现,provided会影响子依赖. 标记为scope:provided的jar在编译和运行时有作用,表明了运行时depen ...

  7. HuTool之判断上传文件的文件类型

    文件类型判断-FileTypeUtil 由来 在文件上传时,有时候我们需要判断文件类型.但是又不能简单的通过扩展名来判断(防止恶意脚本等通过上传到服务器上),于是我们需要在服务端通过读取文件的首部几个 ...

  8. robotframework_javaScript定位

    整理笔记才发现,只有在rebotframework才用过js定位,那么如果有小伙伴在使用js遇到问题,给我留言吧 通过Id定位   name定位 通过标签名查找 HTML 元素 本例查找 id=&qu ...

  9. ZIP压缩与解压

    /**//* * Gary Zhang -- cbcye@live.com * www.cbcye.com * www.quicklearn.cn * cbcye.cnblogs.com */ usi ...

  10. iOS - swift 后使用打包动态库

    WWDC2014上发布的Xcode6 beta版有了不少更新,其中令我惊讶的一个是苹果在iOS上开放了动态库,在Xcode6 Beta版的更新文档中是这样描述的: Frameworks for iOS ...