题目链接: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. 性能测试工具 wrk 使用教程

    文章首发自个人微信公众号:小哈学Java 个人网站地址:https://www.exception.site/wrk 被面试官经常问到之前开发的系统接口 QPS 能达到多少,经常给不出一个数值,支支吾 ...

  2. FTP方式部署Azure Web App

    创建部署凭据 在仪表盘中创建或重置部署凭据,在凭据中设置用户名和密码. 通过FTP方式打开Web根目录 在本地资源管理器中打开FTP地址(例如:ftp://cnws-prod-sha-001.ftp. ...

  3. c# Base64解密加密

    private static string base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ...

  4. winform 跨线程访问问题

    一.问题描述 进行winform 开发我们在进行数据交换时避免不了使用多线程或异步方法,这样操作也将避免不了跨线程对控件进行操作(赋值.修改属性). 下面通过一个测试说明一下问题 点击一个按钮异步对t ...

  5. JAVA设计模式——简单工厂

    工厂模式分为三种:简单工厂模式,工厂方法模式,抽象工厂模式.我看有的书上和有的文章里是分为两种,没有简单工厂. 工厂模式主要的作用是:一个对象在实例化的时候可以选择多个类,在实例化的时候根据一些业务规 ...

  6. JavaScript学习一之数据校验

    JavaScript页面进行数据校验 <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...

  7. JVM内存结构,运行机制

    三月十号,白天出去有事情出去了一天,晚上刚到食堂就接到阿里电话, 紧张到不行,很多基础的问题都不知道从哪里说了orz: 其中关于JVM内存结构,运行机制,自己笔记里面有总结的,可当天还是一下子说不出来 ...

  8. Win10中Vue.js的安装和项目搭建

    一. 提前准备工作 1.Node.js环境 2.Windows10 3.npm(前端包管理工具) 4.webpack(前端资源加载/打包工具) 二. 开始安装 1..下载并安装Node.js 下载地址 ...

  9. 使用 phpstudy 搭建本地测试环境

    最近在为另一个部门配置一个多语言的网站,因为之前他们已经做过 英文和中文两种语言,这次帮他们添加其它几种语言,从GitLab 上拉下来的代码,是php环境做的,需要在本地跑起来,做完测试通过后再一次性 ...

  10. Postman学习之【压力测试】

    Postman请自行下载 下面是在网上随便抓了一个请求地址来做演示,把请求地址填入地址栏,此请求为GET请求.点击Send发送请求,请求结果将会在下方显示出来.每次的请求历史数据,会被记录下来,但是经 ...