I - Nice to Meet You

來源:互聯網
上載者:User

標籤:alt   lse   ||   namespace   無向圖   beta   target   targe   blank   

傳送門

和10-17 B 君的第三題 類似,應該算是簡化版,給出了固定的點。

f[s]表示只考慮連端都在s集合中的邊,s中的固定點(1或者2)能到達整個集合的方案數。

預先處理c[s]表示s集合中的總邊數,轉移就用所有方案減去s集合中有一部分不能到達的方案,也就是枚舉一個子集作為能到達的,這個子集的補集和子集之間的邊方向確定了,補集內的邊隨便選,也就和無向圖每條邊選或者不選等價了。

和無向圖不同的是,1能到達的點的集合為s1,2能到達的點的集合為s2的時候,(s1,s2的補集內的邊隨便定向,補集和s1,s2之間的邊方向唯一確定),s1中的任意點不能於s2中的點有連邊,因為一個點x不在s2中表明它到s2集合內的點的邊都是指向s2的,那麼x若在s1中,s1和s2就聯通了。

一開始一直wa三個點,因為我固定一個點的時候枚舉子集可以為0但是我跳出了。。。

 1 //Achen 2 #include<bits/stdc++.h> 3 #define For(i,a,b) for(int i=(a);i<=(b);i++) 4 #define Rep(i,a,b) for(int i=(a);i>=(b);i--) 5 #define Formylove return 0 6 const int N=32777,p=1e9+7; 7 typedef long long LL; 8 typedef double db; 9 using namespace std;10 int n,m,a[123],b[123],mp[20][20];11 LL pr[123],c[N],f[N],to[N];12 LL ans;13 14 template<typename T> void read(T &x) {15     char ch=getchar(); x=0; T f=1;16     while(ch!=‘-‘&&(ch<‘0‘||ch>‘9‘)) ch=getchar();17     if(ch==‘-‘) f=-1,ch=getchar();18     for(;ch>=‘0‘&&ch<=‘9‘;ch=getchar()) x=x*10+ch-‘0‘; x*=f;19 }20 21 //#define ANS22 int main() {23 #ifdef ANS24     freopen("1.in","r",stdin);25     freopen("1.out","w",stdout);26 #endif27     read(n); read(m);28     pr[0]=1;29     For(i,1,120) pr[i]=2LL*pr[i-1]%p;30     For(i,1,m) {31         read(a[i]); read(b[i]); 32         mp[a[i]][b[i]]++;33         mp[b[i]][a[i]]++;34         c[pr[a[i]-1]+pr[b[i]-1]]++;35     }36     For(i,1,n) {37         For(j,1,n) if(mp[i][j]) to[pr[i-1]]|=pr[j-1];38     }39     int up=pr[n]-1;40     For(i,0,n-1) For(s,1,up) {41         if(!(s&pr[i])) {42             c[s|pr[i]]+=c[s];43             to[s|pr[i]]|=to[s];44         }45     }46     //For(i,1,up) printf("%d : %d\n",i,to[i]);47     f[1]=f[2]=1;48     For(s,3,up) {49         LL t=0;50         for(int ss=((s-1)&s);ss;ss=((ss-1)&s)) {51             if((!(s&2)&&(s&1)&&!(ss&2)&&(ss&1))||(!(s&1)&&(s&2)&&!(ss&1)&&(ss&2))) 52                 t=(t+f[ss]*pr[c[s^ss]]%p)%p;53         }54         if((!(s&2)&&(s&1))||(!(s&1)&&(s&2))) f[s]=(pr[c[s]]-t+p)%p;55     }56     For(s,1,up) if((s&1)&&!(s&2)) {57         int S=(up^s)-2;58         for(int ss=S;;ss=((ss-1)&S)) {59             if((s&to[up^s^ss])!=0||((up^s^ss)&to[s])!=0) {60                 if(!ss) break; else continue;61             }62             ans=(ans+f[s]*f[up^s^ss]%p*pr[c[ss]]%p)%p;63             if(!ss) break;64         }65     }66     printf("%lld\n",(pr[m]-ans+p)%p);67     Formylove;68 }
View Code

 

I - Nice to Meet You

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.