zoukankan      html  css  js  c++  java
  • Bzoj1899: [Zjoi2004]Lunch 午餐

    题面

    传送门

    Sol

    首先显然吃饭久的要排在前面
    之后再来分配队伍,设(f[i][j])表示到第(i)个人,(A)队伍要等(j)的最小吃完饭时间
    那么就是一个简单的背包吧。。。

    # include <bits/stdc++.h>
    # define RG register
    # define IL inline
    # define Fill(a, b) memset(a, b, sizeof(a))
    # define Sqr(x) ((x) * (x))
    using namespace std;
    typedef long long ll;
    const int _(205);
    
    IL ll Read(){
        RG ll x = 0, z = 1; RG char c = getchar();
        for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
        for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
        return x * z;
    }
    
    int n, a[_], b[_], sum[_], f[_][_ * _], ans = 2e9, id[_];
    
    IL bool Cmp(RG int x, RG int y){  return b[x] > b[y];  }
    
    int main(RG int argc, RG char* argv[]){
    	n = Read();
    	for(RG int i = 1; i <= n; ++i) a[i] = Read(), b[i] = Read(), id[i] = i;
    	sort(id + 1, id + n + 1, Cmp);
    	for(RG int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + a[id[i]];
    	Fill(f, 63); f[0][0] = 0;
    	for(RG int i = 1; i <= n; ++i)
    		for(RG int j = 0; j <= sum[i]; ++j){
    			f[i][j] = max(f[i - 1][j], (sum[i] - j) + b[id[i]]);
    			if(j >= a[id[i]]) f[i][j] = min(f[i][j], max(f[i - 1][j - a[id[i]]], j + b[id[i]]));
    		}
    	for(RG int i = 0; i <= sum[n]; ++i) ans = min(ans, f[n][i]);
    	printf("%d
    ", ans);
        return 0;
    }
    
    
  • 相关阅读:
    分页功能
    四个内置对象的作用范围
    include和application
    jsp中的session
    IDC机房的相关常识
    使用dm-cache组合SSD与HDD实现高性价比存储
    负载均衡基本原理与lvs
    秒级别执行脚本的方法
    Tomcat调优
    Nginx调优
  • 原文地址:https://www.cnblogs.com/cjoieryl/p/8318872.html
Copyright © 2011-2022 走看看