• P2577-午餐


     1 #include <bits/stdc++.h>
     2 #define _for(i,a,b) for(int i = (a);i < b;i ++)
     3 #define _rep(i,a,b) for(int i = (a);i > b;i --)
     4 #define INF 0x3f3f3f3f
     5 typedef long long ll;
     6 using namespace std;
     7 inline ll read()
     8 {
     9     ll ans = 0;
    10     char ch = getchar(), last = ' ';
    11     while(!isdigit(ch)) last = ch, ch = getchar();
    12     while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
    13     if(last == '-') ans = -ans;
    14     return ans;
    15 }
    16 inline void write(ll x)
    17 {
    18     if(x < 0) x = -x, putchar('-');
    19     if(x >= 10) write(x / 10);
    20     putchar(x % 10 + '0');
    21 }
    22 struct P
    23 {
    24     int a;
    25     int b;
    26     bool operator < (P se)
    27     {
    28         return this->b > se.b;
    29     }
    30 };
    31 int N;
    32 P a[203];
    33 int dp[203][203*203];
    34 int sum[203];
    35 int main()
    36 {
    37     N = read();
    38     _for(i,1,N+1)
    39         a[i].a = read(),a[i].b = read();
    40     
    41     sort(a+1,a+1+N);
    42     
    43     _for(i,1,N+1) 
    44         sum[i] = sum[i-1]+a[i].a;
    45     memset(dp,0x3f,sizeof(dp));
    46     dp[0][0] = 0;
    47     _for(i,1,N+1)
    48         _for(j,0,sum[i])
    49         {
    50             if(j>=a[i].a)
    51                 dp[i][j] = min(dp[i][j],max(dp[i-1][j-a[i].a],j+a[i].b));
    52             dp[i][j] = min(dp[i][j],max(dp[i-1][j],sum[i]-j+a[i].b));
    53         }
    54     int ans = 0x3f3f3f3f;
    55     _for(i,0,sum[N])
    56         ans = min(ans,dp[N][i]);
    57     write(ans);
    58     return 0;
    59 }
  • 相关阅读:
    vue监听多个变量的方法
    Unicode与JavaScript详解
    两个数组合并的方法
    第13章 事件
    第12章 DOM2和DOM3
    IIS发布WebService的一些常见问题
    Openlayers修改矢量要素并且可捕捉
    Openlayers修改矢量要素
    openlayers画图形返回范围
    前台html与后台php通信(上传文件)
  • 原文地址:https://www.cnblogs.com/Asurudo/p/11429548.html
Copyright © 2020-2023  润新知