Bzoj 3270 Museum expected dp+ Gaussian elimination element

Source: Internet
Author: User

Topic: Given a non-connected graph, two people initially at a certain point, each moment each person will not move or choose to walk, ask two people finally where to meet

The two points (x, y) on the original map become a point on the new graph.

Then make a for the adjacency matrix of the graph (if two people on the same point there is no edge, otherwise by probability transfer), S is the initial row vector (s[(A, b)]=1), ans is the answer line vector

Then there are ans=s+sa+sa^2+sa^3+ ...

=s (i-a^+∞)/(I-A)

=s/(I-A)

So there ans* (i-a) =s

So the i-a of the transfer of Gaussian elimination element can be.

It's like the idea of expelling a pig.

#include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream > #include <algorithm> #define M 440#define P (x, y) (*n-n+ (y)) using namespace Std;struct abcd{int to,next;} Table[m];int head[m],tot;int n,m,a,b;int Degree[m];long double p[m],f[m][m],ans[m];void Add (int x,int y) {Table[++tot]. To=y;table[tot].next=head[x];head[x]=tot;} void gauss_elimination (int n) {int i,j,k;for (i=1;i<=n;i++) {k=i;for (j=i;j<=n;j++) if (Fabs (F[j][i]) >fabs (f[k ][i]) k=j;for (j=i;j<=n+1;j++) swap (f[i][j],f[k][j]); for (k=i+1;k<=n;k++) {long double temp=-f[k][i]/f[i][i]; for (j=i;j<=n+1;j++) f[k][j]+=f[i][j]*temp;}} for (i=n;i;i--) {for (j=i+1;j<=n;j++) f[i][n+1]-=f[i][j]*ans[j];ans[i]=f[i][n+1]/f[i][i];}} BOOL Compare (int x,int y) {return ans[p (x,x)] < Ans[p (y,y)];} int main () {//freopen ("electric.in", "R", stdin);//freopen ("Electric.out", "w", stdout); int i,j,x,y;cin>>n> >m>>a>>b;for (i=1;i<=m;i++) {scanf ("%d%d", &x,&y);d egree[x]++;d egree[y]++; ADD (x, y); ADD (y,x);} for (i=1;i<=n;i++) cin>>p[i];for (x=1;x<=n;x++) for (y=1;y<=n;y++) if (x!=y) {f[p (x, y)][p (x, y)]-=p[x]*p [Y];for (I=head[x];i;i=table[i].next) f[p (x, y)][p (table[i].to,y)]-= (1-p[x])/degree[x]*p[y];for (j=head[y];j;j= Table[j].next) f[p (x, y)][p (x,table[j].to)]-= (1-p[y])/degree[y]*p[x];for (I=head[x];i;i=table[i].next) for (j=head[ Y];j;j=table[j].next) f[p (x, y)][p (table[i].to,table[j].to)]-= (1-p[x]) * (1-p[y])/degree[x]/degree[y];} for (i=1;i<=n*n;i++) for (j=1;j<i;j++) swap (F[i][j],f[j][i]), for (i=1;i<=n*n;i++) f[i][i]+=1;f[p (A, b)][n*n+ 1]=1; Gauss_elimination (N*n); for (i=1;i<=n;i++) cout<<fixed<<setprecision (6) <<ans[p (i,i)]<< "; return 0;}


Bzoj 3270 Museum expected dp+ Gaussian elimination element

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.