Scenic route planning (probability dp)

Scenic Route Planning

Title Description

US group travel team recently plans to launch a new service to various attractions scenic tour route planning, improve visitor satisfaction. One important issue is for a scenic road network to determine the expectations of tourists satisfaction. Based on the user's preference differences, we need to calculate the satisfaction of male and female visitors are tourists.
Resort is described as an n points, without edges to FIG. M (no edge weight, no self-loop). Each dot represents a spot, the i-th tour takes ci-minute spots, tourist satisfaction make men and women tourists increased h1i and h2i (satisfaction with initial values are 0). Each edge represents one way, i th number of edges connected to the two spots xi, yi, and come and go from the attractions xi yi xi yi time it is from ti minutes.
Each visitor can explore the longest in the area of k min, the beginning will randomly into a spot to start the tour through different doors, each tour probability of a complete project, visitors will wait for a randomly selected from the current direct access to attractions and have time to visit sightseeing attractions as the next target (already visited attractions will be because there are a variety of new activities allow visitors to consider again, so we do not distinguish whether the attractions here already visited). If a complete tour attractions, not had time to visit the surrounding attractions, this play is over.
Please calculate y and little sister at the end of the play happy expectations.

Enter a description:

The first line gives an integer of three separated by spaces, respectively, n, m, k (0 < n ≤ 100, 1 * 60 ≤ k ≤ 8 * 60) 
following n lines, each line separated by three spaces integer, respectively, ci, h1i, h2i (10 ≤ ci ≤ 60,0 <h1i, h2i ≤ 100) 
next m lines, each line separated by a space of three integers, respectively, xi, yi, ti (0 <ti ≤ 15)

Output Description:

Two real numbers separated by a space, and y denotes a small part table sister happy desired degree, accurate to five decimal places.
Example 1

Entry

5 4 60
25 12 83
30 38 90
16 13 70
22 15 63
50 72 18
2 1 7
3 1 7
4 3 1
5 3 10

Export

39.20000 114.40000 

topic ideas
common probability dp title, expectations are seeking boys and girls, dp [i] [j] .first minute i j denotes the expectation in points, dp [i] [j] .second represents the probability.
Finally, if a place can not go, we should assign a value to dp [k] [j] .first , final tally dp [k] [i] .first and.

code show as below
#include<bits/stdc++.h>
using namespace std;
int n,m,k,c[102],h[3][101];
pair<double,double> dp[500][101];
vector< pair<int,int> > v[101];
double ans[3];
void find_ans(int x)
{
    memset(dp,0,sizeof(dp));
    for(int i = 1;i<=n;i++)
    {
        dp[c[i]][i].first = double(h[x][i])/n;
        dp[c[i]][i].second = 1.0/n;
    }
    for(int i = 1;i<k;i++)
    {
        for(int j = 1;j<=n;j++)
        {
            int flag = 0;
            int num = 0;
            for(int t = 0;t<v[j].size();t++)
            {
                int p = v[j][t].first;
                int time = v[j][t].second+c[v[j][t].first];
                if(i+time<=k)
                    num++;
            }
            for(int t = 0;t<v[j].size();t++)
            {
                int p = v[j][t].first;
                int time = v[j][t].second+c[v[j][t].first];
                if(i+time<=k&&dp[i][j].first)
                {
                    flag = 1;
                    dp[i+time][p].first+=dp[i][j].first*double(1.0/num)+h[x][p]*dp[i][j].second*double(1.0/num);
                    dp[i+time][p].second+=dp[i][j].second*double(1.0/num);
                }    
            }
            if(!flag)
            {
                dp[k][j].first+=dp[i][j].first;
                dp[k][j].second+=dp[i][j].second;
            }
            
        }
    }
    for(int i = 1;i<=n;i++)
        ans[x]+=dp[k][i].first;
}
int main()
{
    int a1,a2,a3;
    cin>>n>>m>>k;
    for(int i = 1;i<=n;i++)
        cin>>c[i]>>h[1][i]>>h[2][i];    
    for(int i = 1;i<=m;i++)
    {
        cin>>a1>>a2>>a3;
        v[a1].push_back(make_pair(a2,a3));
        v[a2].push_back(make_pair(a1,a3));
    }
    find_ans ( 1 ); 
    find_ans ( 2 ); 
    printf ( " % .5lf% .5lf " , years [ 1 ], years [ 2 ]);
    return  0 ; 
}
 
     

 

 

Guess you like

Origin www.cnblogs.com/loganacmer/p/11331362.html