Travel (thinking title number of combinations)

Travel

This cow off a burst from the card to the end of this question, among autistic + sleep + give up.

After the match sister two or three sentences to say understand, very simple a question.

Game when he had thought about it, if we can find out the city is divided into parts m n, each are connected, then the number of such classifications, and then by its full array, that is, m factorial is the answer, then how to ensure that the "carved out of parts per m Unicom" your life to think on this issue, I kept thinking I felt not enough advanced methods of graph theory their knowledge base, and slowly began to give up.

But the thought of it has been very close distance answer. In fact it is divided into parts qualified m, just from the n-1 m-1 sides picked item, it is naturally divided out. It is easy to think that a similar arrangement of the subject combination of the high school "separator Law", except that here the "broken edge method", can be divided off one side to a, and such broken edge is to ensure that each of the segmented a meet the conditions.

The answer is C [n-1] [m-1] * (m!), And the combination may denominator m! Minutes approximately.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int _n=1e9+7;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        for(int i=0;i<n-1;i++)
            {
                int a ,b;
                scanf("%d%d",&a,&b);
            }
        ll x=1;
        for(int i=0;i<m-1;i++)
        {
            x*=(n-1-i);
            x%=_n;
        }

        cout<< x*m % _n <<endl;
    }
    return 0;
}

 

Guess you like

Origin blog.csdn.net/xuzonghao/article/details/82933488