mcpc2017 The Uncertainty of Politics

5096: The Uncertainty of Politics

時間限制: 1 Sec  內存限制: 128 MB  Special Judge

題目描述

You have an upcoming trip to Washington D.C. and you are fascinated with the intricacies of Congressional committee hearings. You wish to attend as many hearings as possible during your trip, and your local representative has provided you with a pass that will get you into the audience of any hearing. But there are some challenges in planning your schedule.
Specifically:
1. There are many committees, and thus many hearings, some of which take place at overlapping times.
2. While the committees are extremely punctual in terms of when to start a hearing, they are notoriously unpredictable in terms of how long the hearing lasts. Fortunately, rules do not actually allow for a filibuster of a committee hearing, so they cannot last forever.
3. It is considered rude to enter a hearing that is already underway, or to leave a hearing before it is complete. Given that you do not wish to embarrass the representative who provided your tickets, if you attend you must attend the entire hearing. Fortunately, hearings are very near to each other; as soon as one hearing is done, you can immediately join another hearing that is about to start.
Well in advance of your trip, Congress publishes a schedule of hearings, indicating for each one the time s at which the hearing will start, and then values a and b which represent, respectively, the shortest and longest possible length of that particular hearing. You are to assume that the actual length of the hearing will be a uniformly random integer over the inclusive interval [a, b]. 
Your goal is to develop a strategy that maximizes the expected number of hearings that you can attend during your trip. As an example, consider a situation in which there are four hearings with parameters as follows:
For this schedule, the optimal strategy will allow you to achieve an expected value of 2.125 hearings. To achieve this, you begin by attending the NASA hearing, which starts at time 3 and ends with equal probability at either time 5 or time 6 (given the hearing length that is uniformly distributed over {2, 3}). If the NASA hearing does end at time 5 you will immediately head to the oil and gas exploration hearing, and there is a  1/4 chance that hearing will end at time 6, allowing you to make yet a third hearing (about hurricane recovery efforts). If the NASA hearing instead ends at time 6, you will go straight to the hurricane hearing. 
By this strategy you will attend 3 hearings 12.5% of the time and 2 hearings the other 87.5% of the time, and thus expected value of 2.125. Note that if you were to start by attending the social media and elections hearing, you might optimistically make four hearings. However, a careful analysis will demonstrate that if you attend the first hearing, your optimal expected value is only 2.10714.

輸入

The input begins with an integer n that designates the total number of scheduled hearings (1 ≤ n ≤ 104).
Following that are n lines, each containing three integers s, a, and b, respectively representing the start time,minimum length, and maximum length of a hearing, such that 1 ≤ s ≤ 106 and 1 ≤ a ≤ b ≤ 106. The hearings will be listed in nondecreasing order of their start times.

輸出

Display the expected number of hearings of an optimal strategy. Your answer should have an absolute or relative error of at most 10−3.

樣例輸入

4
1 1 7
3 2 3
5 1 4
6 10 10

樣例輸出

2.125

題目大意:有n個聽證會,給定每個會議開始的時間,最早的結束時間和最晚的時間,求最明智的方案的參加聽證會數目的期望值。


蒟蒻的思路:因爲參加每一個聽證會後最優方案的期望值只會收到它之後的聽證會的最優方案的期望值的影響,所以第一反應就是從後往前進行一個DP。對每個聽證會,將它的進行時間分爲長度爲1的m段,每段取在該時刻最大的期望,將一個聽證會的所有時刻的最優值加在一起即爲該聽證會的最優解(如一個聽證會進行時間是3-5時刻,那麼我們分別取3、4、5這三個時刻能取得最大值,再將這三個值加在一起,最後加上該聽證會自身的1,即爲該聽證會的最優解)


#include <bits/stdc++.h>
struct hearings
{
    int s,a,b;
};
double dp[100005];                    //dp[i]爲參加第i個聽證會(不參加第i個之前的聽證會)的最優方案的期望值
hearings z[100005];
int main()
{
    int i,n;
    scanf("%d",&n);
    for (i=0;i<n;i++)
        scanf("%d%d%d",&z[i].s,&z[i].a,&z[i].b);
    for (i=n-1; i>=0; i--)           //從最後一個聽證會往前掃
    {
        int p1,p2,e,k=n-1;
        double maxx=0;
        dp[i]++;                    //選擇第i個聽證會則他本身期望爲1
        e=z[i].s+z[i].a;            //最早結束時間
        p2=z[i].s+z[i].b;            //p2爲該聽證會進行時間我們還未處理的最晚時刻(初始化爲最晚結束時間)
        int m=z[i].b-z[i].a+1;        //聽證會進行時間分爲m段(每段長度)
        while (p2>=e)                //如果該聽證會我們尚未處理完
        {
            while(k>i)                //k爲開始時間晚於我們未處理的時刻的最早聽證會
            {
                if (z[k].s<p2)
                    break;
                if (dp[k]>maxx)        //更新這個時刻我們能取的最優解
                    maxx=dp[k];        
                k--;
            }
            p1=e>z[k].s+1?e:z[k].s+1;    //將最優解不需要更新的時刻合併處理(不處理會TLE)(因爲如果這一段時刻沒有開始的聽證會,則最優解不變)
            dp[i]+=maxx*(p2-p1+1)/m;    
            p2=p1-1;                    //更新p2
        }
    }
    double maxx=0;
    for (i=0;i<n;i++)
        if (dp[i]>maxx)
            maxx=dp[i];
    printf("%.16f",maxx);
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章