hdu3037Saving Beans

开发者福利!热门AI工具限时免费用 购周边即赠Coding Plan Lite,Claude Code、Cursor等20+工具畅享,效率翻倍! 阅读详情

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2610    Accepted Submission(s): 966


Problem Description
Although winter is far away, squirrels have to work day and night to save beans. They need plenty of food to get through those long cold days. After some time the squirrel family thinks that they have to solve a problem. They suppose that they will save beans in n different trees. However, since the food is not sufficient nowadays, they will get no more than m beans. They want to know that how many ways there are to save no more than m beans (they are the same) in n trees.

Now they turn to you for help, you should give them the answer. The result may be extremely huge; you should output the result modulo p, because squirrels can’t recognize large numbers.
 

Input
The first line contains one integer T, means the number of cases.

Then followed T lines, each line contains three integers n, m, p, means that squirrels will save no more than m same beans in n different trees, 1 <= n, m <= 1000000000, 1 < p < 100000 and p is guaranteed to be a prime.
 

Output
You should output the answer modulo p.
 

Sample Input
  
2 1 2 5 2 1 5
 

Sample Output
  
3 3
Hint
Hint For sample 1, squirrels will put no more than 2 beans in one tree. Since trees are different, we can label them as 1, 2 … and so on. The 3 ways are: put no beans, put 1 bean in tree 1 and put 2 beans in tree 1. For sample 2, the 3 ways are: put no beans, put 1 bean in tree 1 and put 1 bean in tree 2.
 

Source
 

#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<list>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
ll qpow(ll a,ll b,ll c)
{
	ll ans=1;
	while(b>0)
	{
		if(b&1)
			ans=ans*a%c;
		a=a*a%c;
		b>>=1;
	}
	return ans;
}
ll fac[100000];
ll fmt(ll a,ll b,ll c)
{
	return fac[a]*qpow(fac[b]*fac[a-b]%c,c-2,c)%c;
}
ll lucas(ll a,ll b,ll c)
{
	ll ans=1;
	while(a>0&&b>0)
	{
		if(a%c<b%c)
			return 0;
		ans=ans*fmt(a%c,b%c,c)%c;
		a/=c;
		b/=c;
	}
	return ans;
}
void create(ll a)
{
	fac[0]=1;
	for(ll i=1;i<a;i++)
		fac[i]=fac[i-1]*i%a;
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		ll n,m,p;
		cin>>n>>m>>p;
		create(p);
		cout<<lucas(n+m,m,p)<<endl;
	}
}


Altium Designer22教程——PCB篇 单纯的0和1信号可能会被其他信号干扰,但压差是不会被影响的,只会影响单根线的信号,采用压差来控制就可以避免干扰。,所以需要修改一下走线宽度,可设置为最小6mil,最大20mil(具体走线宽度可在Tab属性更改)此操作也可以设定适用范围,同线宽规则一样,设置新的规则并适用于所创建的类。注意:导出的不是库文件,而是原理图和PCB文件,需要在AD中提取。,然后设置原理图和PCB元件。总结:在PCB布局中,首先。直角和锐角走线会使传输线的。,最后将各部分模块按照。分组摆放,以实现预布局。进行绘制,设置好间距。 阅读详情

相关推荐

Altium Designer(AD)PCB拼版——两种方法教程

本文详细介绍了PCB拼版的设计要点与操作方法。主要内容包括:拼版目的(解决小尺寸夹持问题、提高利用率、降低成本)和三大连接方式(V-CUT、邮票孔、空心连接条)的特点与参数设置;工艺边设计规范(宽度、定位孔、Mark点等要求);拼版尺寸限制与常见错误检查;以及两种具体拼版操作方法(特殊粘贴和拼版阵列),并附有工艺边、定位孔、Mark点的绘制步骤示意图。同时提供了硬件工程师笔试面试相关资源链接。全文系统阐述了PCB拼版的核心技术和操作流程,为电子设计人员提供了实用指导。

XU157303764的博客 7396

AD24学习笔记-------DYH

AD工程主要由原理图库、原理图、PCB库、PCB四部分组成,对于一个工程的创建即先把工程创建好并进行命名,之后再分别创建其原理图库、原理图、PCB库、PCB四部分,注意创建的同时要使用CTRL+S进行每个部分的保存,命名可以命名为项目名称,统一命名方便整理使用,最后再开始进行每个部分的操作。由于直接画直接边角并不是直角,所以同上,我们先用多边形绘制出一个长方形再对其进行去边框处理,同时调整大小及形状,调整过程中可以将格点设置小一点方便移动,移动完后再调回原来的栅格大小,绘制如下图。

xqhrs232的专栏 894

用InVEST做碳中和规划?手把手教你计算城市碳储量与热岛效应

本文详细介绍了如何利用InVEST模型进行城市碳中和规划的科学评估。通过手把手教学,演示了如何使用该模型的碳存储与城市热岛缓解模块,从数据准备、模型运行到结果解读,量化评估不同规划方案下的碳储量变化与热岛效应缓解潜力,为城市规划者提供科学的决策依据。

weixin_29201313的博客 788

拼板注意事项和步骤

本文讲述了AD软件中拼板的注意事项以及拼板的步骤。

m0_58083051的博客 6709

AD24学习笔记——WZQ

项目的建立、原理图库、原理图、PCB库、PCB。常操作,快捷键使用,熟悉工具的使用。PCB设计:PCB布局,PCB布线。明确目标:用AD做电子设计。原理图:原理图库,原理图的绘制。工程的创建、快捷键的操作等。1、建立项目(注意文件夹名称、保存)多看,多练,对比式学习。1、学习如何操作AD软件。2、用AD进行电子设计。

2301_82344698的博客 2251

hdu3037 Saving Beans

hdu3037 Saving BeansProblem DescriptionAlthough winter is far away, squirrels have to work day and night to save beans. They need plenty of food to get through those long cold days. After some time th...

WHYZ2017 312

HDU 3037 Saving Beans lucas定理小试

分析:不超过m个在n个篮子里,

行走世间,皆为妖怪 630

HDU3037 Saving Beans

组合数 隔板法

a free man 655

hdu 3037——Saving Beans

Saving Beans Time Limit: 6000/3000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8258Accepted Submission(s): 3302 Problem Description Although winter ...

aochuiliu8050的博客 168

HDU 3037 Saving Beans

2016暑期集训2-KHDU 3037 Saving Beans组合数性质,Lucas定理 传送门:HustOJ 传送门:HDU 题意给了n,m,p。把不超过m个相同的松子放入n个不同的树洞,有多少种方法,模p。思路题目相当于求n个数的和不超过m的方案数,即把小于等于m个物品分成n堆。 如果和恰好等于m,那么就等价于方程x1+x2+…+xn = m的解的个数,利用插板法可以得到方案数

P.H.S 315

Saving Beans HDU - 3037(题解)

原题 http://acm.hdu.edu.cn/showproblem.php?pid=3037 题目大意 题目要求把i颗豆(0<=i<=m)放进n个洞里有多少种情况. 题目分析 这道题可以看作是在m颗豆里面按顺序插入n+1个板,就是把这m颗豆分成n+1堆,其中n堆是要放入洞中的,还有1堆是不放进洞中的.这时候情况有(m+1)(m+2)...(m+n+1),又因为这些板...

weixin_30338497的博客 134

hdu3037Saving Beans lucas定理

hdu3037 lucas 对组合数取模 lucas(n,m)=C(n%mod,m%mod)*lucas(n/mod,m/mod)%mod; lucas(n,0)=1; #include #include using namespace std; __int64 jc[100010]; __int64 exgcd(__int64 a,__int64 b,__int64

Time flies 1217

hdu 3037 Saving Beans(组合数学)

hdu 3037 Saving Beans 题目大意:n个数,和不大于m的情况,结果模掉p,p保证为素数。 解题思路:隔板法,C(nn+m)多选的一块保证了n个数的和小于等于m。但是n,m很大,所以用到Lucas定理。 #include #include #include using namespace std; typedef long long ll; ll n, m,

不慌不忙、不急不躁 1100

HDU3037 Saving Beans

题目大意:共T个测试点,每个测试点中,给定n、m,求将不超过m个种子放入n个坑的方案总数,最后答案对质数p取模。 数据范围:1 <= n, m <= 1000000000, 1 < p < 100000。 思路:原题意即求方程x1+…+xn=m解的个数,因为中间的每一项均可为0,故两面同时将加上n,转换成为x1+…+xn+n=m+n,即x1’+…+xn’=m+n,其中每一项至少为1,则由隔板法可知,

Little_Flower_0的博客 788

HDU3037 Saving Beans Lucas 定理+逆元

HDU3037 Saving Beans 题目相当于求n个数的和不超过m的方案数。 如果和恰好等于m,那么就等价于方程x1+x2+...+xn = m的解的个数,利用插板法可以得到方案数为: (m+1)x(m+2)...(m+n-1)  = C(m+n-1,n-1) = C(m+n-1,m) 现在就需要求不大于m的,相当于对i = 0,1...,m对C(n+i-1,i)求和,根据公式C(n...

Qianyri的博客 294

HDU3037Saving Beans

Lucas的裸题,学习一个。 #include<bits/stdc++.h> #define N 100010 using namespace std; typedef long long ll; ll a[N]; int p; ll pow(ll y,int z,int p){ y%=p;ll ans=1; for(int i=z;i;...

di679520024669的专栏 168

[HDU3037] Saving Beans Lucas定理

传送门Problem DescriptionAlthough winter is far away, squirrels have to work day and night to save beans. They need plenty of food to get through those long cold days. After some time the squirrel family...

LvYanchang的博客 332
上一篇: csu1527: Bounty Hunter
下一篇: 组合数对素数取模 Lucas定理
Last0rder
博客等级 码龄18年 50粉丝 325原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值