B - Average Gym - 101161B 组合数学
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 组合数学的更多相关文章
- training 2
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.136 Average Precision (AP) @[ IoU ...
- [GYM 100492A] Average Convex Hull 凸包好题
大致题意: 给出一个点集,其中有一个点有相同的几率会被删除,求删除之后的点集够成的凸包上的点的平均数. 首先看到题目,可以考虑枚举删除的点,将其凸包上前后两点以及两点间凸包内所有点构建凸包,因为凸包内 ...
- Codeforces Gym 100338H High Speed Trains 组合数学+dp+高精度
原题链接:http://codeforces.com/gym/100338/attachments/download/2136/20062007-winter-petrozavodsk-camp-an ...
- Codeforces Gym 100431B Binary Search 搜索+组合数学+高精度
原题链接:http://codeforces.com/gym/100431/attachments/download/2421/20092010-winter-petrozavodsk-camp-an ...
- 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 ...
- Gym 100425A Luggage Distribution (组合数学,二分)
一开始想着球盒模型,数据范围大,递推会GG. 用凑的方法来算方案.往n个小球之间插两个隔板,方案是(n-1)*(n-2)/2,不区分盒子,三个盒子小球数各不相同的方案数被算了6次(做排列), 两个相同 ...
- Codeforces Gym 100418K Cards 组合数学
CardsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action? ...
- Gym 100548F Color 给花染色 容斥+组合数学+逆元 铜牌题
Problem F. ColorDescriptionRecently, Mr. Big recieved n flowers from his fans. He wants to recolor th ...
- 2015 asia xian regional F Color (容斥 + 组合数学)
2015 asia xian regional F Color (容斥 + 组合数学) 题目链接http://codeforces.com/gym/100548/attachments Descrip ...
随机推荐
- 【转】Pro Android学习笔记(二四):用户界面和控制(12):Style和Theme
目录(?)[-] 静态格式 代码中设定 Style Theme 静态格式 在res/values中设置静态的Style,在资源中设置静态Style可使用的HTML格式有<i> <u& ...
- Queue——C#浅谈
1.Queue定义 System.Collections.Queue类表示对象的先进先出集合,存储在 Queue(队列) 中的对象在一端插入,从另一端移除. 2.优点 1.能对集合进行顺序处理(先进先 ...
- %.*s, printf
%.*s_百度搜索 c语言%.*s是什么_百度知道 *用来指定宽度,对应一个整数 .(点)与后面的数合起来 是指定必须输出这个宽度,如果所输出的字符串长度大于这个数,则按此宽度输出,如果小于,则输出实 ...
- HTML5小知识
1.HTML5一种“妥协的”语法 2.特点: 标签不区分大小写 元素可以省略结束标签 元素属性可以省略属性值 属性的属性值可以不适用引号
- MongoDB一些基本的命令
Win+R进入Dos命令窗口,输入cmd,进入MongoDB exe文件的所在目录,比如我的在E:\MongoDB\bin,分别执行:“E:”回车,然后:"cd mongodb/bin&qu ...
- [hdu1176]免费馅饼(数塔dp)
题意:中文题,不解释了 = = 解题关键:逆推,转化为数塔dp就可以了 dp[i][j]表示在i秒j位置的最大值. 转移方程:$dp[i][j] = \max (dp[i + 1][j],dp[i + ...
- oracle上课 学习2 oracle 游标 存储过程 有用
1.1. 训练描述 使用游标,打印emp中20号部门的所有员工的信息 操作步骤答案 declare cursor c_emp is select * from emp where deptno=10 ...
- 关闭QtCreator的vim风格编辑模式
今天不小心点到了键盘的快捷键Alt+V,使QtCreator进入了vim风格编辑模式,导致快捷键拷贝粘贴都不正常,找了下资料才发现是这个问题.具体操作如下: 打开QtCreator去掉下列位置的勾选或 ...
- 每次选中数组中的N条数据, 如果让每条数据被选中的次数做到平均??
经常有这样的需求, 有一组数据, 每次展示其中的1条或N条,希望每条数据展示量可以做到平均. 一开始想依次展示每条数据并做记录,整组数据全展示一遍之后清除记录, 然后一直循环下去. 实现的过程中又觉得 ...
- Good Bye 2014 B. New Year Permutation(floyd )
题目链接 题意:给n个数,要求这n个数字小的尽量放到前面,求一个最小的. 给一个矩阵s[i][j]==1,表示位置 i 的数字可以和 位置 j 的数字交换. 分析: 刚开始用的是3个循环,每次都找一个 ...