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. centos6.5升级默认的Mysql到5.5方法

    0.用lsb_release -a 查看linux系统的版本 1.官网下载bundle或rpm版2.解压 tar -xvf MySQL-xxx.tar或 MySQL-server-xxx.rpm和My ...

  2. 【转】 Pro Android学习笔记(五八):Preferences(2):CheckBoxPreference

    目录(?)[-] CheckBox Preference xml文件 设备的存贮文件 复合preference 在ListPreference的例子中显示的是单选,如果是多选,可采用CheckBoxP ...

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

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

  4. unittest 执行测试脚本输出测试报告

    import unittestimport HTMLTestRunnertest as HTMLTestRunner#获取路径path = './'#创建测试套件,读取测试脚本suite = unit ...

  5. Java常见设计模式之适配器模式

    在阎宏博士的<JAVA与模式>一书中开头是这样描述适配器(Adapter)模式的: 适配器模式把一个类的接口变换成客户端所期待的另一种接口,从而使原本因接口不匹配而无法在一起工作的两个类能 ...

  6. uboot的relocation原理详细分析

    转自:http://blog.csdn.net/skyflying2012/article/details/37660265 最近在一直在做uboot的移植工作,uboot中有很多值得学习的东西,之前 ...

  7. java报表开发之报表总述

    转自:https://blog.csdn.net/u011659172/article/details/40504271?utm_source=blogxgwz6

  8. tomcat solr 限制ip

    <Context path="/solr" reloadable="false" docBase="/var/www"> < ...

  9. Linux Screen超简明教程

    1.安装Screen 大多数情况下,系统已经安装好了screen.如果没有,可以用下面的命令来安装: CentOS系统中执行:yum install screen Debian/Ubuntu系统执行: ...

  10. mysql 表名作为存储过程变量

    mysql默认不支持表名作为变量名,如下所示 delimiter $$ DROP procedure IF EXISTS getDataByDbName $$ CREATE procedure get ...