题意:求n有顺序的划分为k个数的方案数.思路:显然这个就是一个组合公式,隔板法。可以把问题转化为x1+x2+…..xk = n 这个多元一次方程上。然后这个解就是C(n+k-1,k-1)
这道题n,k范围都是1e6。
我们可以预处理出阶乘,然后求对应的组合数,注意这里需要取Mod,用下逆元就好啦.参考code:/*
#pragma warning (disable: 4786)
#pragm...
分类:
其他好文 时间:
2015-08-27 23:08:49
阅读次数:
138
题意:求n个数的排列,前m个中有k个在自己的位置上的方法数。思路:设D[n]为n个元素的错排数.
于是我们有D[1] = 0 D[2] = 1;
D[n] = (D[n-1] + D[n-2]) * (i-1)
考虑问题本身,我们首先从前m个数选k个数不动.即C(m,k)。对于没有选的前m中的m-k个数肯定是参与了错排,而后面n-m个数中参加错排的个数不定,所以我们枚举一个后面n-m个数中选出...
分类:
其他好文 时间:
2015-08-27 23:03:48
阅读次数:
685
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1403代码:#include
#include
#include
#include
#include
#include
#include <sstre...
分类:
其他好文 时间:
2015-08-27 07:15:08
阅读次数:
183
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1184根据一些要求建图即可代码:#include
#include
#include
#include
#include
#include
#incl...
分类:
其他好文 时间:
2015-08-27 07:13:00
阅读次数:
184
链接:http://www.lightoj.com/volume_showproblem.php?problem=1201最大独立集= 顶点数- 最大匹配代码:#include
#include
#include
#include
#include
#include
#...
分类:
其他好文 时间:
2015-08-26 22:28:06
阅读次数:
200
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1149代码:#include
#include
#include
#include
#include
#include
#include <sstre...
分类:
其他好文 时间:
2015-08-26 20:06:37
阅读次数:
170
DescriptionSometimes some mathematical results are hard to believe. One of the common problems is the birthday paradox. Suppose you are in a party whe...
分类:
其他好文 时间:
2015-08-21 23:09:05
阅读次数:
158
lightOJ 1317 Throwing Balls into the Baskets(期望)解题报告题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88890#problem/A题目:DescriptionYou probab...
A -ATime Limit:2000MSMemory Limit:32768KB64bit IO Format:%lld & %lluDescriptionYou probably have played the game "Throwing Balls into the Basket". It ...
分类:
其他好文 时间:
2015-08-21 21:26:01
阅读次数:
167
DescriptionYou probably have played the game "Throwing Balls into the Basket". It is a simple game. You have to throw a ball into a basket from a cert...