#include <bits/stdc++.h> using namespace std; const int N = 1000001; int l,r,n,m,w; double dp[N][2]; double res; int main(){ ios::sync_with_stdio(false); while(cin>>n>>m>>l>>r){ for (int i = 0; i < n; i++) { dp[i][0]=dp[i][1]=0; } //memset(dp,0,sizeof(dp)); 用这句TLE res=0; dp[0][0]=1; for (int i = 1; i <= m; i++) { cin>>w; for (int j = 0; j < n; j++) { dp[j][i%2]=(dp[(j+n-w)%n][!(i%2)]+dp[(j+w)%n][!(i%2)])/2; } } for (int i = l-1; i < r; i++) { res+=dp[i][m%2]; } if (n==0&&m==0&&l==0&&r==0) continue; cout<<fixed<<setprecision(4)<<res<<endl; } return 0; }
原文:https://www.cnblogs.com/limitedInfinite/p/14696297.html