Codeforces Round #277.5 (Div. 2) --E. Hiking (01分数规划)

E. Hiking
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by its picturesqueness, so for the i-th rest point the distance from the start equals xi, and its picturesqueness equals bi. The traveler will move down the river in one direction, we can assume that he will start from point 0 on the coordinate axis and rest points are points with coordinates xi.

Every day the traveler wants to cover the distance l. In practice, it turns out that this is not always possible, because he needs to end each day at one of the resting points. In addition, the traveler is choosing between two desires: cover distance l every day and visit the most picturesque places.

Let's assume that if the traveler covers distance rj in a day, then he feels frustration , and his total frustration over the hike is calculated as the total frustration on all days.

Help him plan the route so as to minimize the relative total frustration: the total frustration divided by the total picturesqueness of all the rest points he used.

The traveler's path must end in the farthest rest point.

Input

The first line of the input contains integers n, l (1 ≤ n ≤ 1000, 1 ≤ l ≤ 105) — the number of rest points and the optimal length of one day path.

Then n lines follow, each line describes one rest point as a pair of integers xi, bi (1 ≤ xi, bi ≤ 106). No two rest points have the same xi, the lines are given in the order of strictly increasing xi.

Output

Print the traveler's path as a sequence of the numbers of the resting points he used in the order he used them. Number the points from 1 to n in the order of increasing xi. The last printed number must be equal to n.

Sample test(s)
input
5 9
10 10
20 10
30 1
31 5
40 10
output
1 2 4 5 
贴一篇博客http://blog.csdn.net/hhaile/article/details/8883652 原文作者没有找到。
上面的博客看了之后,此题就是一道水水的 二分 + DP 了。
 1 #include <cmath>

 2 #include <cstdio>

 3 #include <cstdlib>

 4 #include <cstring>

 5 #include <algorithm>

 6 using namespace std;

 7 typedef long long ll;

 8 const int inf = 0x3f3f3f3f;

 9 const double eps = 1e-10;

10 const int maxn = 1005;

11 int pos[maxn],b[maxn],pre[maxn],n,l;

12 double dp[maxn];

13 double check(double x)

14 {

15     memset(pre,0,sizeof(pre));

16     for (int i = 1; i <= n; i++)

17     {

18         dp[i] = inf;

19         for (int j = 0; j < i; j++)

20         {

21             double tmp = dp[j] + sqrt(abs(.0 + pos[i] - pos[j] - l)) - x * b[i];

22             if (tmp < dp[i])

23             {

24                 dp[i] = tmp;

25                 pre[i] = j;

26             }

27         }

28     }

29     return dp[n];

30 }

31 void print_path(int x)

32 {

33     if (pre[x])

34         print_path(pre[x]);

35     printf("%d ",x);

36 }

37 int main(void)

38 {

39     #ifndef ONLINE_JUDGE

40         freopen("in.txt","r",stdin);

41     #endif

42     while (~scanf ("%d%d",&n,&l))

43     {

44         for (int i = 1; i <= n; i++)

45             scanf ("%d%d",pos+i,b+i);

46         double ua = 0,ub = 1e10;

47         while (ub - ua > eps)

48         {

49             double mid = (ua + ub)/2;

50             if (check(mid) >= 0)

51                 ua = mid;

52             else

53                 ub = mid;

54         }

55        print_path(n);

56     }

57     return 0;

58 }

 

你可能感兴趣的:(codeforces)