牛客国庆集训派对Day3H-Travel
题解:
这一题一开始以为是树上问题,其实仔细一想与树一点关系都没有。
m1m-1条边将这个树划分为mm个区域,这就代表了mm次旅游,然后求其全排列就是答案。
ans=Cn1m1m!ans=C_{n-1}^{m-1}*m!
CodeCode:

#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);
    }
}

相关文章:

  • 2021-10-03
  • 2022-01-04
  • 2021-10-25
  • 2022-02-14
  • 2022-01-20
  • 2021-09-28
  • 2021-05-18
  • 2021-05-27
猜你喜欢
  • 2021-06-15
  • 2021-09-13
  • 2021-03-30
  • 2021-10-26
  • 2021-12-09
  • 2021-12-10
  • 2021-11-03
相关资源
相似解决方案