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 ...
随机推荐
- 洛谷【P2115】[USACO14MAR]破坏Sabotage
我对二分的理解:https://www.cnblogs.com/AKMer/p/9737477.html 题目传送门:https://www.luogu.org/problemnew/show/P21 ...
- 接口Comparator和Comparable的区别和联系
1. Comparator 和 Comparable 相同的地方 他们都是java的一个接口, 并且是用来对自定义的class比较大小的. 什么是自定义class: 如 public class Pe ...
- 自定义echart tooltip格式
formatter: function (tipData) { return tipData[0].name + '</br>' + '<span style="displ ...
- 使用union来遍历结构体中的成员
前几天和实验室的同学讨论问题的时候发现他使用的一段数据校验的代码自己以前没有接触过,今天有空就把它整理了一下. #include <stdio.h> #include <stdlib ...
- CodeForces 492A Vanya and Cubes
A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Git for Windows,TortoiseGit支持WinXP的最后版本及下载方法
TortoiseGit兼容Windows XP和Windows Server 2003的最后版本: TortoiseGit 1.8.16.0 (https://download.tortoisegit ...
- 新建用户无法通过SecureSRT进行ssh登录到远程linux (zz)
root新建了一个普通用户oracle,并且设置了密码:通过SecureSRT连接远程linux,连不上[注:用的是之前新建过的以root为用户名的SecureSRT已有连接,如192.168.1.1 ...
- App集成极光推送步骤
一.准备: 1.1注册极光开发者账号 1.2添加应用,获取AppKey 1.3下载提供的demo,demo中的AppKey已自动生成为你自己的AppKey 二.集成: 2.1第一种方式:自动集成 Mo ...
- STL特性总述——写在前面
所谓的容器,见名知意,容纳其他数据的"器具": 特点 1)支持泛型: 2)保存副本:本质上传入对象的拷贝. 3)内存托管 :构建对象于堆,无需人工干预,自动管理内存的生存周期. S ...
- 使用Realsense D400 camera系列跑rgbdslamv2
Ubuntu16.04,kinetic 在之前写的博文<如何使用ROS查找rgbdslam代码包框架的输入>中提到,一开始不知道整体框架,只用感性认识去跑rgbdslamv2的包,是一个天 ...