牛客国庆集训派对Day3H-Travel

版权声明:不念过去,不畏未来,一切都是过眼云烟。 https://blog.csdn.net/qq_34531807/article/details/83212999


题解:
这一题一开始以为是树上问题,其实仔细一想与树一点关系都没有。
m 1 m-1 条边将这个树划分为 m m 个区域,这就代表了 m m 次旅游,然后求其全排列就是答案。
a n s = C n 1 m 1 m ! ans=C_{n-1}^{m-1}*m!
C o d e Code:

#include<iostream>
using namespace std;
const int mod=1e9+7;
int n,m;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&m);
        int a,b;
        for(int i=0;i<n-1;++i)scanf("%d%d",&a,&b);
        long long ans=1;
        for(int i=n-1;i>n-m;--i)ans=1ll*i*ans%mod;
        printf("%lld\n",1ll*ans*m%mod);
    }
}

猜你喜欢

转载自blog.csdn.net/qq_34531807/article/details/83212999