指望dpsb題···很少說了ios
#include<iostream> #include<cstdio> #include<cstdlib> #include<ctime> #include<cctype> #include<string> #include<cstring> #include<algorithm> using namespace std; const int N=1e5+5; double f[N]; int n,m,to[N]; inline int R(){ char c;int f=0; for(c=getchar();c<'0'||c>'9';c=getchar()); for(;c<='9'&&c>='0';c=getchar()) f=(f<<3)+(f<<1)+c-'0'; return f; } int main(){ //freopen("a.in","r",stdin); while(scanf("%d%d",&n,&m)){ if(n==0&&m==0) break; memset(to,0,sizeof(to));memset(f,0,sizeof(f));int a,b; for(int i=1;i<=m;i++) a=R(),b=R(),to[a]=b; for(int i=n-1;i>=0;i--){ if(to[i]){ f[i]=f[to[i]];continue; } for(int j=1;j<=6;j++) f[i]+=(f[i+j]+1)/6; } printf("%0.4f\n",f[0]); } return 0; }