求助卡常
查看原帖
求助卡常
88735
寒鸽儿楼主2021/3/30 18:52

rt , 写丑t了 , 吸个氧跑的飞快。 不会卡常 , 求求.

/*
  sol.cpp -- P2340 [USACO03FALL]Cow Exhibition G
*/

#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define repp(i,a,b) for(int i=(a);i<(b);++i)
#define perr(i,a,b) for(int i=(a);i>(b);--i)
#define pb push_back
#define rz resize

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<ldb> VD;

template<class T> inline void read(T &x) {
    x = 0; char ch;
    do{ch=getchar();} while(ch<'0'||ch>'9');
    do{x=(x<<3)+(x<<1)+(x&15),ch=getchar();} while(ch>='0'&&ch<='9');
}
int Mod = 1;
inline int Inc(int x, int y) { return (x += y) < Mod ? x : x - Mod; }
inline int Dec(int x, int y) { return (x -= y) < 0 ? x + Mod : x; }
inline int Mul(int x, int y) { return 1ll * x * y % Mod; }
inline int Power(int x, int y) {
    int ret = 1%Mod;
    for(; y; y>>=1) {
        if(y&1) ret=(ll)ret*x%Mod;
        x=(ll)x*x%Mod;
    }
    return ret;
}

template<class T> inline T abs(T x) { return x > 0 ? x : -x; }
template<class T> inline void cmin(T &x, T y) { x = x > y ? y : x; }
template<class T> inline void cmax(T &x, T y) { x = x > y ? x : y; }

template<class T>
class BIT { public:
    const int maxN;
    vector<T> c;
    BIT(int size) : maxN(size) { c.rz(size + 1); }
    void add(int x, T v) { for(; x <= maxN; x += x&(-x)) c[x] += v; }
    T qry(int x) { T ret = 0; for(; x; x -= x&(-x)) ret += c[x]; return ret; }
};

const int maxn = 400, maxm = 2000, maxl = maxn*maxm, inf = 0x3f3f3f3f;
int f[maxl*2+1000], g[maxl*2+1000];

// inline void show() {
//     rep(i,-16,30) if(f[tr(i)] < -100) printf("qq "); else printf("(%d,%d) ", i, f[tr(i)]); puts(""); puts("");
// }
int main() {
    if(fopen("yl.in", "r")) {
        freopen("yl.in", "r", stdin);
        freopen("yl.out", "w", stdout);
    }
    int n, a, b;
    scanf("%d", &n);
    rep(i,0,maxl*2) f[i] = g[i] = -inf;
    // show();
    rep(i,1,n) {
        scanf("%d %d", &a, &b); cmax(g[a+maxl], b);
        for(int j = -maxl; j <= maxl; ++j) if(j + a <= maxl && j + a >= -maxl) cmax(g[j+a+maxl], f[j+maxl] + b);
        rep(j,0,2*maxl) cmax(f[j], g[j]);
        // show();
    }
    int ans = 0;
    rep(j,0,maxl) if(f[j+maxl] >= 0 && ans < f[j+maxl] + j) ans = f[j+maxl] + j;
    printf("%d\n", ans);
    return 0;
}

2021/3/30 18:52
加载中...