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. docker数据卷(volume)

    1.什么是数据卷volume https://blog.csdn.net/dream_broken/article/details/52314993 为了了解什么是Docker Volume,首先我们 ...

  2. 【转】Pro Android学习笔记(十八):用户界面和控制(6):Adapter和AdapterView

    目录(?)[-] SimpleCursorAdapter 系统预置的layout ArrayAdapter 动态数据增插删排序 自定义TextView风格 其他Adapter AdapterView不 ...

  3. AlteraFPGA使用通用SPIFlash - 张亚群的技术专栏 - 博客频道 - CSDN.NET

    AlteraFPGA使用通用SPIFlash - 张亚群的技术专栏 - 博客频道 - CSDN.NET Altera器件有EPCS系列配置器件,其实,这些配置器件就是我们平时通用的SPIFlash,据 ...

  4. java 设置Cookie值

    原文地址:http://blog.csdn.net/lansetiankong12/article/details/52622654 /** * 读取所有cookie * 注意二.从客户端读取Cook ...

  5. 盒模型的auto值

    浮动在盒模型的auto值 属性 常规流 浮动 margin-left:auto 尽量撑满包含块 0px margin-right:auto 尽量撑满包含块 0px margin-top:auto 0p ...

  6. unity 查找游戏中隐藏的物体

    在Hierarchy 有时会隐藏一些游戏物体,我们需要在游戏的时候将其激活状态变为true 我们发现通过  GameObject.Find("隐藏物体名字") 是查找不到隐藏对象的 ...

  7. Boost Python学习笔记(五)

    你将学到什么 在C++中调用Python代码时的返回值问题 基础类型 修改Python脚本(build/zoo.py) def rint(): return 2 def rstr(): return ...

  8. shell之hello world

    [root@localhost sh]#vi hello.sh //编辑 .sh 文件 #The first program #!/bin/bash echo 'hello world' [root@ ...

  9. 微信小程序小结(1) ------ 前后端交互及wx.request的简易封装

    微信小程序的应用目前越来越多,不管喜欢与否我们都应该了解一些.废话不多,直接干货. 做项目自然避免不了前后端的交互,小程序在调试过程中需要在先在:小程序公众平台--设置--开发设置中,将要从后台请求的 ...

  10. 【转】processOnServer

    源地址:http://blog.csdn.net/dl020840504/article/details/8856853