HDU-5001 walk 2014 Anshan Network Competition e question

Source: Internet
Author: User

Enumerate all vertices that cannot be passed through in sequence. The sum of probabilities of all other vertices is the probability that the vertex will not pass through.

#include <iostream>#include <cstdio>#include <queue>#include <algorithm>#include <cstring>#include <cmath>#include <queue>#include <iomanip>#include <vector>#define LL long long #define inf 1<<29using namespace std;struct node{int u,v;int next;}edge[250000];int n,m,d;int num;int head[55];int sum[55];double dp[11111][55];void addedge(int u,int v){edge[num].u=u;edge[num].v=v;edge[num].next=head[u];head[u]=num++;edge[num].u=v;edge[num].v=u;edge[num].next=head[v];head[v]=num++;}int main(){int t;int u,v;scanf("%d",&t);while(t--){scanf("%d%d%d",&n,&m,&d);num=0;memset(head,-1,sizeof(head));memset(dp,0,sizeof(dp));memset(sum,0,sizeof(sum));for(int i=0;i<m;i++){scanf("%d%d",&u,&v);addedge(u,v);sum[u]++;sum[v]++;}for(int i=1;i<=n;i++){memset(dp,0,sizeof(dp));for(int ii=1;ii<=n;ii++){dp[0][ii]=1.0/n;}for(int j=0;j<d;j++){for(int l=1;l<=n;l++){if(dp[j][l]!=0&&l!=i){int len=sum[l];double temp=dp[j][l]/len;//cout<<temp<<endl;for(int k=head[l];k!=-1;k=edge[k].next){int v=edge[k].v;dp[j+1][v]+=temp;}}}}double s=0;for(int j=1;j<=n;j++){if(j!=i){s+=dp[d][j];}}printf("%.9f\n",s);}}return 0;}


HDU-5001 walk 2014 Anshan Network Competition e question

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.