Hunting Contest (week Associations tournament)

Links: http://139.9.84.16/problem/1006

Description

Fat house and his wife have recently obsessed "people were hunting the monster: the world", and now they are ready to hold hunting contest!

Hunting Contest only allowed to use two weapons too knives and bows and arrows, two weapons were placed in two warehouses. Hunting need to line up to pick a knife too satisfied or satisfied with the bow in a warehouse, and then start hunting.

There are a lot of computers, so pick a good wife after they are able to begin hunting weapons, but each warehouse at most only one of them to enter.

Fat house wife who would like to arrange divided into two teams and line up the order. Two teams are in parallel independently of each other.

For the first fat house ii i wife, no matter what weapons, pick weapons are needed XiX_i the X- i time, hunting all need YiY_i the Y- i time.

From the moment 00 starts at 0, ask my wife what had the fastest time to complete the hunt?

 

Input

The first line of a positive integer NN n-expressed NN n-wife

Next NN n-lines of two integers represent XiX_i X- I and YiY_i the Y I

1&lt;n≤3001 &lt; n \leq 3001<n300

2≤Xi, Yi≤2332 \ leq X_i, Y_i \ leq 233 2 X i , Y i 2 3 3

 

Output

A line output integer fastest to complete all hunting and when

Sample Input 1

5
2 2
7 7
1 3
6 4
8 5

Sample Output 1

17

 

Solution: Obviously y big on team head, please xi, yi values ​​are small, the total time is very small, because it is two queues, as long as a team which will be able to know the total dp optimal solution , F [i] [j] denotes the i-th before the optimal solution when the j-th second,

  State transition equation: f [i] [j] = min (max (f [i-1] [j-xi], j + yi)); f [i] [j] = min (max (f [i- 1] [j], sum [i] -j + yi));

#include <bits/stdc++.h>
using namespace std;

const int maxn=305;
struct Node{
    int x, y;
    bool operator <(const Node &a) const{
        return y>a.y;
    }
}a[maxn];

int f[maxn][maxn*maxn], sum[maxn];
int n;

int main ()
{
    scanf("%d", &n);
    for(int i=1; i<=n; i++)
        scanf("%d%d", &a[i].x, &a[i].y);
    sort(a+1, a+1+n);
    for(int i=1; i<=n; i++)
        sum[i]=sum[i-1]+a[i].x;
    memset(f, 0x3f, sizeof(f));
    f[0][0]=0;
    for(int i=1; i<=n; i++)
    {
        for(int j=a[i].x; j<=sum[n]; j++)
            f[i][j]=min(f[i][j], max(f[i-1][j-a[i].x], j+a[i].y));
        for(int j=0; j<=sum[n]; j++)
            f[i][j]=min(f[i][j], max(f[i-1][j], sum[i]-j+a[i].y));
    }
    int ans=1<<30;
    for(int j=0; j<=sum[n]; j++)
        years = min (years, f [n] [j]);
    printf("%d\n", ans);
    return 0;
}
View Code

 

 

Guess you like

Origin www.cnblogs.com/Yokel062/p/11634805.html