P5520 [yLOI2019] 青原樱 (组合数学)
题目传送门
题意: 给你一个长度为n的路,m棵互不相同的树,要求每两颗数之间必须留空一个位置,问你有多少种方法种树。
思路: 因为两颗树之间必须有空隔,一共m棵树也就是m-1个空隔,我们把这些空隔抽出来,于是还剩下n-m+1个位置,我们只需要在n-m+1个位置中选取m个位置,最后把m-1个空隔插入就行了,注意这题是排列就行。
#include
#define endl '\n'
#define null NULL
#define ls p<<1
#define rs p<<1|1
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define int long long
#define pii pair
#define ull unsigned long long
#define all(x) x.begin(),x.end()
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ct cerr<<"Time elapsed:"<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
char *fs,*ft,buf[1<<20];
#define gc() (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<20,stdin),fs==ft))?0:*fs++;
inline int read(){int x=0,f=1;char ch=gc();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=gc();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=gc();}
return x*f;}
using namespace std;
const int N=1e7+5;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const double eps=1e-7;
const double PI=acos(-1);
int a(int m,int n,int p)
{int res=1;for(int i=n-m+1;i<=n;i++)res=res*i%p;return res;
}
signed main()
{int type,n,m,p;cin>>type>>n>>m>>p;cout<<a(m,n-m+1,p)<<endl;
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
