链接:

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. lambda表达式笔记

    前几天一位好友分享了一篇文章,其中讲到了lambda表达式,正好最近看了一些内容,就做做笔记吧... lambda表达式服务于函数式接口,如果需要一个函数式接口的对象时,就可以用lambda表达式代替 ...

  2. Python--代码1(接口测试:测试用例从数据库读取写到yaml文件中)

    一. 从数据库中读取全部接口,并写入yaml文件 数据库中的数据存储格式如下图: import pymysql import os import json # from ruamel import y ...

  3. Linux命令xargs的使用

    ls | xargs catls | xargs -I {} cat {}  大写I,指定参数的替换符号为{} 自定义

  4. Oracle 11g 总结篇2

    第一部分: 字段名的别名用""括起来,如:last_name as "姓名". 去除重复:在投影的字段名前加上 distinct 就可以了. 比如:select ...

  5. 【LEETCODE】44、509. Fibonacci Number

    package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...

  6. Spring主要用到两种设计模式

    Spring主要用到两种设计模式 1.工厂模式 Spring容器就是实例化和管理全部Bean的工厂. 工厂模式可以将Java对象的调用者从被调用者的实现逻辑中分离出来. 调用者只关心被调用者必须满足的 ...

  7. java之hibernate之helloworld

    这篇文章,会一步一步的演示hibernate的使用. 目录结构如下: 1.新建java项目 2.增加一个lib文件夹,并把 hibernate必须的jar包 和 数据库驱动包 一起复制进去 然后把hi ...

  8. 【阿里云开发】- 安装JDK

    1.阿里云轻量服务器入口 https://swas.console.aliyun.com/?spm=5176.2020520001.1011.2.29ff4bd3P4AEDc#/servers 2.使 ...

  9. Jmeter学习笔记(十一)——定时器

    默认情况下,Jmeter线程在发送请求之间没有间歇.不设置定时器,短时间内会产生大量访问请求,导致服务器被请求淹没,利用Jmeter进行压测时,一般会和定时器一起,控制请求的吞吐量和并发数. 一.定时 ...

  10. SVN 提交失败 非LF行结束符

    来源:http://programerni.diandian.com/post/2012-09-06/40037220960 我使用svn一直很顺利,今天在改了两个地方之后,提交时输入了两句话(只有两 ...