http://codeforces.com/gym/101161/attachments

今天被卡常了,其实是自己对组合数技巧研究的不够。

如果是n, m <= 1e5的,然后取模是质数,那么可以用费马小定理。

如果n, m都比较小,那么其实是直接杨辉三角。不用逆元那些。

这题的思路是,枚举每一一个ave,然后总和就是n * ave

相当于方程  x1 + x2 + .... + xn = n * ave中,在0 <= x[i] <= full的情况下,不同解的个数中,使得x[i] == ave的个数。每有一个x[i] == ave

ans++

首先x1 + x2 + ..... + xn = n * ave在0 <= x[i] <= full有多少个不同的解,可以容斥出来,这里就不说了,复杂度O(n)

可以看看这个,http://www.cnblogs.com/liuweimingcprogram/p/6091396.html

然后怎么统计有多少个ans

考虑每一个的贡献,因为每个人的贡献是独立的,

如果x[1] == ave,有多少种情况?就是x2 + x3 + ..... + xn = ave * n - ave的合法解的个数种。

x[2] == ave同理,所以ans += n * 合法总数。

就比如ave = 1, 序列1、1、1中,贡献是3,其中x1 = 1的时候,x2 = x3 = 1一种,然后x2 = 1, x1 = x3 = 1又是一种。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#define X first
#define Y second
#define lson T[rt].l
#define rson T[rt].r
#define clr(u,v); memset(u,v,sizeof(u));
#define in() freopen("data.txt","r",stdin);
#define out() freopen("ans","w",stdout);
#define Clear(Q); while (!Q.empty()) Q.pop();
#define pb push_back using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int maxn = 1e6 + ;
LL C[ + ][ + ];
const int MOD = 1e9 + ;
LL calc(int n, int en, int sum) {
if (sum < ) return ;
LL all = C[sum + n - ][n - ];
for (int i = ; i <= n; ++i) {
int fuck = sum - i * (en + ) + n - ;
if (fuck < ) break; //notice
if (i & ) {
all = (all + MOD - C[n][i] * C[fuck][n - ] % MOD) % MOD;
} else all = (all + MOD + C[n][i] * C[fuck][n - ] % MOD) % MOD;
}
return all;
}
int n, full;
void work() {
LL ans = ;
for (int i = ; i <= full; ++i) { // 枚举ave
ans += n * calc(n - , full, i * n - i) % MOD;
ans %= MOD;
}
cout << ans << endl;
} int main() {
#ifdef local
in();
#else
#endif
C[][] = ;
C[][] = , C[][] = ;
for (int i = ; i <= ; ++i) {
int en = min(, i);
C[i][] = ;
for (int j = ; j <= en; ++j) {
C[i][j] = (C[i - ][j - ] + C[i - ][j]) % MOD;
}
}
while (scanf("%d%d", &n, &full) > && (n + full)) work();
return ;
}

B - Average Gym - 101161B 组合数学的更多相关文章

  1. training 2

    Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.136 Average Precision (AP) @[ IoU ...

  2. [GYM 100492A] Average Convex Hull 凸包好题

    大致题意: 给出一个点集,其中有一个点有相同的几率会被删除,求删除之后的点集够成的凸包上的点的平均数. 首先看到题目,可以考虑枚举删除的点,将其凸包上前后两点以及两点间凸包内所有点构建凸包,因为凸包内 ...

  3. Codeforces Gym 100338H High Speed Trains 组合数学+dp+高精度

    原题链接:http://codeforces.com/gym/100338/attachments/download/2136/20062007-winter-petrozavodsk-camp-an ...

  4. Codeforces Gym 100431B Binary Search 搜索+组合数学+高精度

    原题链接:http://codeforces.com/gym/100431/attachments/download/2421/20092010-winter-petrozavodsk-camp-an ...

  5. Gym - 101147G G - The Galactic Olympics —— 组合数学 - 第二类斯特林数

    题目链接:http://codeforces.com/gym/101147/problem/G G. The Galactic Olympics time limit per test 2.0 s m ...

  6. Gym 100425A Luggage Distribution (组合数学,二分)

    一开始想着球盒模型,数据范围大,递推会GG. 用凑的方法来算方案.往n个小球之间插两个隔板,方案是(n-1)*(n-2)/2,不区分盒子,三个盒子小球数各不相同的方案数被算了6次(做排列), 两个相同 ...

  7. Codeforces Gym 100418K Cards 组合数学

    CardsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action? ...

  8. Gym 100548F Color 给花染色 容斥+组合数学+逆元 铜牌题

    Problem F. ColorDescriptionRecently, Mr. Big recieved n flowers from his fans. He wants to recolor th ...

  9. 2015 asia xian regional F Color (容斥 + 组合数学)

    2015 asia xian regional F Color (容斥 + 组合数学) 题目链接http://codeforces.com/gym/100548/attachments Descrip ...

随机推荐

  1. 洛谷 P4547 & bzoj 5006 随机二分图 —— 状压DP+期望

    题目:https://www.luogu.org/problemnew/show/P4547 https://www.lydsy.com/JudgeOnline/problem.php?id=5006 ...

  2. android开发之Bitmap 、byte[] 、 Drawable之间的相互转换

    一.相关概念 1.Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable) ...

  3. JavaScript-Tool:my97datepicker

    ylbtech-JavaScript-Tool:my97datepicker 1.返回顶部 1. 2.下载 https://files.cnblogs.com/files/storebook/java ...

  4. IIS应用池保持激活工具开发

    之前的 开源一个定时任务调度器 webscheduler 中涉及的定时调用应用已经开始在正式环境中启用,发布到IIS下进行测试,发现一旦应用长时间没有访问(大约半个多小时)就会引发 Applicati ...

  5. 谷歌浏览器的input自动填充出现黄色背景解决方案(在已经输入内容之后)

    当你之前提交过表单,再次获取input焦点时,会有一个记录之前填写过的文本的下拉列表式的自动填充效果且带有黄色背景, 这个填充功能本身是没什么问题的,但是谷歌浏览器给了个莫名其妙的黄色背景,用css样 ...

  6. Queue——C#浅谈

    1.Queue定义 System.Collections.Queue类表示对象的先进先出集合,存储在 Queue(队列) 中的对象在一端插入,从另一端移除. 2.优点 1.能对集合进行顺序处理(先进先 ...

  7. MySQL的变量--系统变量、状态变量

    MySQL的变量分为以下两种:1)系统变量:配置MySQL服务器的运行环境,可以用show variables查看2)状态变量:监控MySQL服务器的运行状态,可以用show status查看 一.系 ...

  8. Flask15 远程开发环境搭建、安装虚拟机、导入镜像文件、创建开发环境、pycharm和远程开发环境协同工作

    1 安装VM虚拟机 待更新... 2 导入镜像文件 待更新... 3 启动虚拟机 4 远程连接虚拟机 4.1 安装xShell软件 待更新... 4.2 创建一个新的连接 4.2.1 在虚拟机中获取虚 ...

  9. Pig Flatten 解包操作,解元组

    Flatten Operator The FLATTEN operator looks like a UDF syntactically, but it is actually an operator ...

  10. Java垃圾回收机制(Garbage Collection)

    引用博客地址:http://www.cnblogs.com/ywl925/p/3925637.html 以下两篇博客综合描述Java垃圾回收机制 第一篇:说的比较多,但是不详细 http://www. ...