组合数+逆元 A - Chat Group Gym - 101775A
题目链接:https://cn.vjudge.net/contest/274151#problem/A
具体思路:我们可以先把所有的情况算出来,为2^n.然后不合法的情况减去就可以了.注意除法的时候要用到逆元.
AC代码:
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<stdio.h>
#include<queue>
using namespace std;
# define ll long long
# define inf 0x3f3f3f3f
const int maxn = 100000+100;
# define mod 1000000007
ll quickpow(ll t1,ll t2)
{
t2--;
ll ans=t1;
while(t2)
{
if(t2&1)ans=ans*t1%mod;
t1=t1*t1%mod;
t2>>=1;
}
return ans;
}
ll inv(ll t)
{
return quickpow(t,mod-2);
}
int main()
{
int T;
int Case=0;
scanf("%d",&T);
while(T--)
{
ll n,m;
scanf("%lld %lld",&n,&m);
ll t1=n,t2=n+1;
ll temp=quickpow(2,n);
if(n<m)
{
printf("Case #%d: %lld\n",++Case,0);
}
else
{
for(int i=2; i<=m-1; i++)
{
t1=t1*(n-i+1)%mod*inv(i)%mod;
t2=(t2+t1)%mod;
}
printf("Case #%d: %lld\n",++Case,(temp-t2+mod)%mod);
}
}
return 0;
}
组合数+逆元 A - Chat Group Gym - 101775A的更多相关文章
- Gym - 101775A Chat Group 组合数+逆元+快速幂
It is said that a dormitory with 6 persons has 7 chat groups ^_^. But the number can be even larger: ...
- Gym 101775A - Chat Group - [简单数学题][2017 EC-Final Problem A]
题目链接:http://codeforces.com/gym/101775/problem/A It is said that a dormitory with 6 persons has 7 cha ...
- Chat Group gym101775A(逆元,组合数)
传送门:Chat Group(gym101775A) 题意:一个宿舍中又n个人,最少k(k >= 3)个人就可以建一个讨论组,问最多可以建多少个不同的讨论组. 思路:求组合数的和,因为涉及除法取 ...
- A - Chat Group Gym-101775A
题目连接:https://codeforces.com/gym/101775/problem/A 题解:就是累加组合数 但是直接由K累加到N肯定会TLE ,所以我们不妨判断不能组成group的情况,即 ...
- NOIP2011多项式系数[快速幂|组合数|逆元]
题目描述 给定一个多项式(by+ax)^k,请求出多项式展开后x^n*y^m 项的系数. 输入输出格式 输入格式: 输入文件名为factor.in. 共一行,包含5 个整数,分别为 a ,b ,k , ...
- 2016 ACM/ICPC Asia Regional Shenyang Online 1003/HDU 5894 数学/组合数/逆元
hannnnah_j’s Biological Test Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K ...
- HDU 6044--Limited Permutation(搜索+组合数+逆元)
题目链接 Problem Description As to a permutation p1,p2,⋯,pn from 1 to n, it is uncomplicated for each 1≤ ...
- 牛客练习赛17 C 操作数(组合数+逆元)
给定长度为n的数组a,定义一次操作为: 1. 算出长度为n的数组s,使得si= (a[1] + a[2] + ... + a[i]) mod 1,000,000,007: 2. 执行a = s: 现在 ...
- Problem B. Harvest of Apples(杭电2018年多校+组合数+逆元+莫队)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6333 题目: 题意:求C(n,0)+C(n,1)+……+C(n,m)的值. 思路:由于t和n数值范围太 ...
随机推荐
- ping不通的常见原因和解决办法
Ping是Windows.Unix和Linux系统下的一个命令.ping也属于一个通信协议,是TCP/IP协议的一部分.利用“ping”命令可以检查网络是否连通.如果ping不通则可以通过以下方式寻找 ...
- js控制iframe高度自动撑开
<iframe src="index.html" width="100%" name="" id="myiframe&quo ...
- bzoj1211-树的计数
题意 给出 \(n\) 和长度为 \(n\) 的数列 \(d\) 表示每个点的度数,问有多少颗满足要求的树. 分析 这题是prufer编码的应用. prufer编码是对一个带标号无根树的刻画,生成方式 ...
- 【poj2154】Color Polya定理+欧拉函数
题目描述 $T$ 组询问,用 $n$ 种颜色去染 $n$ 个点的环,旋转后相同视为同构.求不同构的环的个数模 $p$ 的结果. $T\le 3500,n\le 10^9,p\le 30000$ . 题 ...
- request之setAtrribute
当在servlet中有request.SetAtrribute("AtriruteName",AtrributeValue)语句时,在jsp页面获取AtrributeValue有两 ...
- 【明哥报错簿】之 mybatis异常invalid comparison: java.util.Date and java.lang.String
背景:数据库为postgresql,表字段属性为timestamp格式 原因是mybatis 3.3.0中对于时间参数进行比较时的一个bug. 如果拿传入的时间类型参数与空字符串''进行对比判断则会引 ...
- 转: 解决【Unable to make the session state request to the session state server】
错误描述: Unable to make the session state request to the session state server. Please ensure that the A ...
- [HEOI2014]逻辑翻译
ywy_c_asm的良心题解 是道好题 体现了二进制位的形象递归思想,以及将FWT的思路(都是拆位分治)用到题目中的典范 可以暴力高斯消元.完全没有利用2^N以及+-1的良好性质 发现项数,方程和二进 ...
- 【组合数学】【P4996】 咕咕咕
Description 小 F 注意到,自己总是在某些情况下会产生歉意.每当他要检查自己的任务表来决定下一项任务的时候,如果当前他干了某些事情,但是没干另一些事情,那么他就会产生一定量的歉意--比如, ...
- Python3 字典 clear()方法
Python3 字典 描述 Python 字典 clear() 函数用于删除字典内所有元素. 语法 clear()方法语法: dict.clear() 参数 NA. 返回值 该函数没有任何返回值. ...