题目链接: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. AI - TensorFlow - 过拟合(Overfitting)

    过拟合 过拟合(overfitting,过度学习,过度拟合): 过度准确地拟合了历史数据(精确的区分了所有的训练数据),而对新数据适应性较差,预测时会有很大误差. 过拟合是机器学习中常见的问题,解决方 ...

  2. 理解滑动平均(exponential moving average)

    1. 用滑动平均估计局部均值 滑动平均(exponential moving average),或者叫做指数加权平均(exponentially weighted moving average),可以 ...

  3. 阿里云Ubuntu下安装、配置权限和导入本地mongodb

    ---恢复内容开始--- 第一部分:首先先在Ubuntu下安装好mongodb,步骤如下: 首先我们需要借助远程管理工具链接到阿里云上的ubuntu系统,接着进行如下操作 一.导出软件源的公钥 sud ...

  4. Golang之变量去哪儿

    目录 什么是逃逸分析 为什么要逃逸分析 逃逸分析是怎么完成的 逃逸分析实例 总结 参考资料 写过C/C++的同学都知道,调用著名的malloc和new函数可以在堆上分配一块内存,这块内存的使用和销毁的 ...

  5. 让你的ASP.NET Core应用程序更安全

    让你的ASP.NET Core应用程序更安全 对于ASP.NET Core应用程序,除了提供认证和授权机制来保证服务的安全性,还需要考虑下面的一些安全因素: CSRF 强制HTTPS 安全的HTTP ...

  6. XSS 绕过技术

    XSS Cross-Site Scripting(XSS)是一类出现在 web 应用程序上的安全弱点,攻击者可以通过 XSS 插入一 些代码,使得访问页面的其他用户都可以看到,XSS 通常是可以被看作 ...

  7. [Linux] deepin与nginx

    deepin Linux Deepin 是一个基于 DEB 包管理的一个独立操作系统,和那些 Ubuntu(下个大版本是基于debian开发) 的衍生版仅仅只是换主题.调整ISO预置的软件包不同.Li ...

  8. DS控件库 在Combobox中嵌入远程桌面

    本示例演示DS开放式下拉列表控件中加入一个RDP远程桌面控件. 先在VS工具箱中添加COM控件Microsoft RDP Client Control,后面的Version版本可以适当高点. 然后将R ...

  9. vs2017和vs2019专业版和企业版

    步骤:打开vs2017,依次点击--->帮助----->注册产品 专业版: Professional: KBJFW-NXHK6-W4WJM-CRMQB-G3CDH 企业版: Enterpr ...

  10. AngularJS 截取字符串

    参考文章:https://blog.csdn.net/u010234516/article/details/54631525 //过滤器 app.filter('textLengthSet', fun ...