Bzoj 4013 HNOI2015 Experiment comparing tree-shape dp+ Combinatorial mathematics

Source: Internet
Author: User

Topic: Given a picture, each edge has ' = ' and ' < ' two properties, each point in the degree of a maximum of 1, to find out how many of this graph can be pressed into the ' = ' and ' < ' connected sequence
I only post code ~ ~
Find your own Search ~ ~

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define M#define MOD 1000000007using namespace STD;structabcd{intTo,next;} TABLE[M];intHead[m],tot;intN,m;intC[M][M],F[M][M];intA[M][M],DEGREE[M];intV[m],t;voidADD (intXintY) {table[++tot].to=y;    TABLE[TOT].NEXT=HEAD[X]; Head[x]=tot;}namespaceunion_find_set{intFA[M];intFind (intx) {if(!fa[x]| | FA[X]==X)returnFa[x]=x;returnFa[x]=find (Fa[x]); }voidUnion (intXintY) {x=find (x); Y=find (y);if(x==y)return;    Fa[x]=y; }}voidPretreatment () {intI,j; for(i=0; i<=n;i++) {c[i][0]=1; for(j=1; j<=i;j++) c[i][j]= (c[i-1][j]+c[i-1][j-1])%mod; }}voidDFS (intx) {intI v[x]=t; for(I=head[x];i;i=table[i].next) {if(v[table[i].to]==t)Throw true;if(V[table[i].to])Continue;       DFS (table[i].to); }}voidTREE_DP (intx) {inti,j,k,l; f[x][0]=1; for(I=head[x];i;i=table[i].next) {TREE_DP (table[i].to);Static intG[M];memset(g,0,sizeofg); for(j=1; j<=n;j++) for(k=0; k<=j;k++) for(l=j-k;l<=j;l++) (G[j] + = (Long Long) f[x][k] * F[table[i].to][l]% mod * c[j][k]% mod * c[k][k+l-j]% mod)%=mod;memcpy(F[x],g,sizeofg); } for(i=n+1; i;i--) f[x][i]=f[x][i-1]; f[x][0]=0;}intMain () {using namespaceUnion_find_set;intI,j,x,y;Charp[Ten];Cin>>n>>m; Pretreatment (); for(i=1; i<=m;i++) {scanf("%d%s%d", &x,p,&y);if(p[0]==' = ') Union (x, y);ElseADD (x, y); } for(x=1; x<=n;x++) for(I=head[x];i;i=table[i].next) A[find (x)][find (table[i].to)]=1;memset(Head,0,sizeofHead); tot=0; for(i=1; i<=n;i++) for(j=1; j<=n;j++)if(A[i][j]) ADD (I,J), degree[j]++; for(i=1; i<=n;i++)if(Find (i) ==i&&!v[i]) {Try{++t;            DFS (i); }Catch(BOOL)            {cout<<0<<endl;return 0; }        } for(i=1; i<=n;i++)if(Find (i) ==i&&!degree[i]) ADD (0, i); TREE_DP (0);intans=0; for(i=1; i<=n+1; i++) (ans+=f[0][i])%=mod;cout<<ans<<endl;return 0;}

Bzoj 4013 HNOI2015 Experiment comparing tree-shape dp+ Combinatorial mathematics

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.