2016.4.06test:problem2:bzoj: Search + Combinatorial Math _oi

Source: Internet
Author: User

The main idea: there is a complete picture of n points, each side has a 1~l weight, bear children want to know how many such graphs, so that from 1 to n the shortest short-circuit for k, because such a diagram may be a lot of you just output the number of solutions to 1e9+7 after the result can be. N,k<=12,l<=10^9

Analysis: N,k is very small, l large, considering the enumeration, enumerating the number of points with the shortest short-circuit as I a[i]

For two points i,j if DI=DJ, then this side of the Benquan is arbitrary, if DI<DJ, then the edge of the right can not be less than dj-di, so as to ensure that the shortest path is not changed, then the edge of the tmp1= (L (di-dj) +1) species may, which DI>=DJ

However, it is found that the shortest circuit property of Di must have at least one J to guarantee Dj+w (J,i) =di.

Because the Benquan W (j,i) of the Dj+w (j,i) >di has tmp2= (L (di-dj)) species may

Therefore, TMP1 and TMP2 respectively after the TMP1-TMP2 is to ensure the number of the shortest short-circuit nature of Di

Note that if di>=k, you don't have to control tmp2.

Finally, because we are enumerating the number of points with the shortest path to I, there is no order, so multiply it by (n-2).

But found that the same point in the same I will repeat, so there is a factorial divided by each a[i]

#include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <
Algorithm> using namespace std;
int a[15],b[15],n,k,l,t,cnt,bit[15],tt;
Long ans;
const int mod=1000000007;
		void Dfs (int x,int y) {if (x==k+1) {if (y+2!=n&&k==l) return;
        cnt=0;
        for (int i=1;i<=n;i++) for (int j=1;j<=a[i];j++) b[++cnt]=i;
        B[++cnt]=k;
        for (int i=1;i<=n-y-2;i++) b[++cnt]=k+1;
        Long Long ret=1;
            for (int i=1;i<=cnt;i++) {long long tmp1=1,tmp2=1; for (int j=0;j<i;j++) if (B[j]<b[i]) tmp1=tmp1* (L (b[i]-b[j)) +1%mod, tmp2=tmp2* (L (b[i]-b[j))%m
            Od
			if (b[i]<=k) ret=ret* (tmp1-tmp2+mod)%mod;
            else Ret=ret*tmp1%mod;
        for (int j=0;j<i;j++) if (b[j]==b[i]) ret=ret*l%mod;
		int q=tt;
		for (int i=1;i<x;i++) q/=bit[a[i]];
        Q/=BIT[N-Y-2];
        Ans= (ans+ret*q)%mod;
 Return   for (int i=0; i<=n-2-y; i++) {a[x]=i;
    DFS (X+1,y+i);
    int main () {bit[0]=1;
    for (int i=1; i<=12; i++) bit[i]=bit[i-1]*i;
    scanf ("%d%d%d", &n,&k,&l);
    if (l<k) {puts ("0"); return 0;}
    if (n==2) {puts ("1"); return 0;} Tt=1;
    for (int i=2;i<n-1;i++) tt*=i;
    DFS (1,0);
cout<<ans<<endl;
 }



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.