Bzoj 3925: [Zjoi2015] After the earthquake fantasy Township (probability)

Source: Internet
Author: User

CLJ is like out of the CTSC on the things, it seems to have to find time to take his several problems to do

First of all, F (x) is the probability of the answer >x, so it's the answer to get this thing from 0 to 1 points.

F (x) <=> edge less than x probability that the graph can not be connected

This is a bit difficult to find, consider the probability of the graph

Remember F (s) for the probability of the set S Unicom, then F (s) =1-sigma (f (S ') * (1-x) ^cnt) (s ' s ' belongs to the and S ' must contain a point k,cnt for the number of sides of the link s ' with CS s ')

It can be found that f (s) is a polynomial and it can be integral.

Since still useless on the 64-bit evaluation system, double or not, had to use __float128, relatively slow

CODE:

#include <cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<vector>using namespacestd;typedef Vector<__float128>Ploy;ployoperator+(ploy X,ploy y) {ploy ans (max (x.size (), Y.size ()),0);  for(intI=0; I<ans.size (); i++) {        if(I<x.size ()) ans[i]+=X[i]; if(I<y.size ()) ans[i]+=Y[i]; }    returnans;} Ployoperator-(ploy X,ploy y) {ploy ans (max (x.size (), Y.size ()),0);  for(intI=0; I<ans.size (); i++) {        if(I<x.size ()) ans[i]+=X[i]; if(I<y.size ()) ans[i]-=Y[i]; }    returnans;} Ployoperator*(ploy X,ploy y) {ploy ans (x.size ()+y.size ()-1,0);  for(intI=0; I<x.size (); i++)          for(intj=0; J<y.size (); j + +) Ans[i+j]+=x[i]*Y[j]; returnans;}BOOLb[1040];p Loy f[1040],quick[ -];intn,m;structedges{intx, y;} e[ -];p Loy One (1,1); inlinevoidprint (ploy x) {printf ("%d\n", X.size ());  for(intI=0; I<x.size (); i++) printf ("%LF",Double(X[i])); printf ("\ n");}voiddpintx) {    if(B[x])return ; B[X]=1; Ploy TMP (0,0);  for(intI=1;i< (1&LT;&LT;N); i++) {        if(! (i&1))Continue; if((i&x)!=i)Continue; if(i==x)Continue; intj=x^i; intCnt=0;  for(intk=1; k<=m*2; k++)             if(i& (1<<e[k].x) &&j& (1&LT;&LT;E[K].Y)) cnt++;        DP (i); TMP=tmp+f[i]*quick[cnt]; } F[x]=one-tmp;} __float128 Cal (ploy x) {__float128 ans=0;  for(intI=0; I<x.size (); i++) ans+=x[i]*1.0/(i+1); returnans;}intMain () {scanf ("%d%d",&n,&m); quick[0]=One ; quick[1]=ploy (2,0); quick[1][0]=1; quick[1][1]=-1;  for(intI=2; i<=m;i++) quick[i]=quick[i-1]*quick[1];  for(intI=1; i<=m;i++) {        intx, y; scanf ("%d%d",&x,&y); X--, y--; E[i*2-1]=(edges) {x, y}; E[i*2]=(edges) {y,x}; } b[1]=1; f[1]=One ; DP ((1<<n)-1); Ploy ans=one-f[(1<<n)-1]; printf ("%.6lf\n",Double(Cal (ANS))); return 0;}

Bzoj 3925: [Zjoi2015] After the earthquake fantasy Township (probability)

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.