1. 程式人生 > >UESTC 電子科大專題訓練 DP-E

UESTC 電子科大專題訓練 DP-E

概率 tdi ble 中文 cnblogs pro push color wap

UESTC 1652

題意:中文題

思路:遍歷每一公裏,然後計算每個車道對後一公裏做出的貢獻,最邊上的車道特判,遍歷完所有車道後判斷如果車道上有障礙,那麽這公裏的的這個車道的概率為0,數據比較水,如果數據大可以用矩陣快速冪對每2個障礙之間用矩陣快速冪優化,這裏就不寫了

AC代碼:

#include "iostream"
#include "iomanip"
#include "string.h"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "set"
#include "map"
#include 
"algorithm" #include "stdio.h" #include "math.h" #define ll long long #define bug(x) cout<<x<<" "<<"UUUUU"<<endl; #define mem(a) memset(a,0,sizeof(a)) #define mp(x,y) make_pair(x,y) #define pb(x) push_back(x) using namespace std; const long long INF = 1e18+1LL; const int inf = 1e9+1e8;
const int N=1e5+100; const ll mod=1e9+7; double dp[2][30005],ans; int ma,n,m,k,a,b,p; vector<int> pp[1005]; int main(){ //ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>m>>k>>n>>p; for(int i=1; i<=k; ++i){ cin>>a>>b; pp[b].pb(a); ma
=max(ma,b); } dp[0][p]=1; double *now=dp[0], *nex=dp[1]; for(int i=1; i<=ma; ++i){ for(int j=1; j<=m; ++j){ if(j==1){ nex[j]+=now[j]/2; nex[j+1]+=now[j]/2; } else if(j==m){ nex[j]+=now[j]/2; nex[j-1]+=now[j]/2; } else{ nex[j]+=now[j]/3; nex[j+1]+=now[j]/3; nex[j-1]+=now[j]/3; } } for(auto j : pp[i]){ nex[j]=0; } swap(now,nex); memset(nex,0,sizeof(dp[0])); } for(int i=1; i<=m; ++i){ ans+=now[i]; } printf("%.6f\n",ans); return 0; }

UESTC 電子科大專題訓練 DP-E