• UESTC 电子科大专题训练 DP-E


    UESTC 1652

    题意:中文题

    思路:遍历每一公里,然后计算每个车道对后一公里做出的贡献,最边上的车道特判,如果计算当前车道可以由前1公里的哪些车道做出贡献那么需要特判很多,但是如果计算当前车道对后1公里做出的贡献只需要特判最边上2个车道即可,遍历完所有车道后判断如果车道上有障碍,那么这公里的的这个车道的概率为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
    ",ans);
        return 0;
    }
  • 相关阅读:
    html5 悬浮提示框
    ajax 接收json
    ajax 发送参数
    jquery无刷新请求ajax
    jQuery 发送 ajax json 请求
    html5 三级联动菜单
    iframe 用法
    html5 复制文字
    bootstrap表单按回车会自动刷新页面的问题
    jquery版本不兼容问题
  • 原文地址:https://www.cnblogs.com/max88888888/p/7230808.html
Copyright © 2020-2023  润新知