题目链接:http://lightoj.com/volume_showproblem.php?problem=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= and k=. There are  solutions. They are

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
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. Input
Input starts with an integer T (≤ ), denoting the number of test cases. Each case contains two integer n ( ≤ n ≤ ) and k ( ≤ k ≤ ). Output
For each case, print the case number and the result modulo . Sample Input
Output for Sample Input Case :
Case :
Case :
Case :

题目大意:求n有顺序的划分为k个数的方案数.

分析:显然这个就是一个组合公式,隔板法。可以把问题转化为x1+x2+…..xk = n 这个多元一次方程上。然后这个解就是C(n+k-1,k-1) 
这道题n,k范围都是1e6。 
我们可以预处理出阶乘,然后求对应的组合数,注意这里需要取Mod,用下逆元就好啦.

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include <map>
#include <string>
#include <vector>
#include<iostream>
using namespace std;
#define N 3000006
#define INF 0x3f3f3f3f
#define LL long long
#define mod 1000000007
LL arr[N];
void Init()
{
arr[] = ;
for(int i=;i<=N;i++)
{
arr[i] = (arr[i-]*i)%mod;
arr[i] %= mod;
}
}
LL quick(LL a, LL b)
{
a = a%mod;
LL ans = ;
while(b)
{
if(b&)
ans = ans*a%mod;
a = a*a%mod;
b /= ;
}
return ans %mod;
}
LL solve(LL a, LL b, LL c)
{
if(b>a)
return ;
return arr[a] * (quick(arr[b] * arr[a-b],c-)) %mod;///利用乘法逆元
}
int main()
{
Init();
int T;
int con=;
scanf("%d",&T);
while(T--)
{
LL n,k;
scanf("%lld %lld",&n,&k);
printf("Case %d: %lld\n",con++,solve(n+k-,k-,mod));///Cn-k+1(k-1);
}
return ;
}

(light oj 1102) Problem Makes Problem (组合数 + 乘法逆元)的更多相关文章

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

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

  2. hdu5698瞬间移动-(杨辉三角+组合数+乘法逆元)

    瞬间移动 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  3. Light OJ 1004 - Monkey Banana Problem(DP)

    题目大意: 给你一菱形的数字阵,问从最上面走到最下面所能获得的最大值是多少? #include<cstdio> #include<cstring> #include<io ...

  4. Light OJ 1102

    题意: 给你一个数 N , 求分成 K 个数 (可以为 0 ) 的种数: 思路: 类似 在K个抽屉放入 N 个苹果, 不为0, 就是 在 n-1 个空隙中选 m-1个: 为 0, 就可以先在 K 个抽 ...

  5. light oj 1067 费马小定理求逆元

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1067 1067 - Combinations Given n differen ...

  6. lightoj 1102 - Problem Makes Problem

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

  7. Light OJ 1067 Combinations (乘法逆元)

    Description Given n different objects, you want to take k of them. How many ways to can do it? For e ...

  8. Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖

    标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...

  9. CodeForces 300C Beautiful Numbers(乘法逆元/费马小定理+组合数公式+高速幂)

    C. Beautiful Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

随机推荐

  1. Python基础(文件操作)

    文件读取: #文件读取方式一 f=open("a.txt","r+",encoding="utf8") data=f.read() prin ...

  2. Linux知识要点大全(第二章)

    第二章   linux操作系统安装与配置主要内容 1:vmware虚拟机安装与使用 2:Linux系统安装前准备 3:Linux Centos 系统的安装 4:Centos 6.8的登录和关闭 5:C ...

  3. 一次生产 CPU 100% 排查优化实践

    前言 到了年底果然都不太平,最近又收到了运维报警:表示有些服务器负载非常高,让我们定位问题. 还真是想什么来什么,前些天还故意把某些服务器的负载提高(没错,老板让我写个 BUG!),不过还好是不同的环 ...

  4. NavUtils【底部虚拟导航栏工具类】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 获取底部虚拟导航栏的高度值 效果图 代码分析 checkDeviceHasNavigationBar(Context context ...

  5. C# WebRequest.Create 锚点“#”字符问题

    背景 在与后台API接口对接时,如将网页Url作为参数请求数据时,如果是锚点参数,则会丢失. 锚点参数 请求通过WebRequest.Create创建一个WebRequest: var uri = & ...

  6. 什么是5G,看了这篇文章你就彻底懂了

    人类已经经历了六次信息技术革命为: 第一次:语言的使用 让信息可以分享 第二次:文字的创造 让信息可以记录 第三次:印刷术的发明 让信息可以传得更远 第四次:无线电的发明 让信息可以远距离实时传输 第 ...

  7. es6 generator函数

    es6 新增了Generator函数,一种异步编程的解决方案 回顾一下,es6 提供了新的遍历方法,for of ,适用于各种数据集合,统一了遍历操作,原生支持for of 集合的数据集合有.数组,字 ...

  8. asp.net core 今日所得

    ViewBag中文变量被编码.乱码. 解决方法: @Html.Raw(@ViewBag.XX) 在 Startup.cs 的 ConfigureServices() 方法中添加下面的一行代码: ser ...

  9. java工作流引擎证照库类型的流程设计 实现方案与演示案例

    关键词:.Net开源工作流    工作流引擎   工作流引擎常用信息存储  流程前置导航 证照库的概念&应用场景: 我们在梳理流程的时候,会发现有一些流程的发起是基于一个实体信息的. 比如:纳 ...

  10. Windows下配置Git多账号github码云

    Windows下配置Git多账号github码云 1.配置了全局用户名和邮箱 $ git config --global user.email "你的邮箱" $ git confi ...