LibreOJ #6217. 扑克牌

二次联通门 : LibreOJ #6217. 扑克牌

/*
    LibreOJ #6217. 扑克牌

    背包。。。。
    
    回到家之后简直了。。。sb题想半天
*/
#include <cstdio>
#include <iostream>


const int BUF = 10000020;
char Buf[BUF], *buf = Buf;

void read (int &now)
{
    for (now = 0; !isdigit (*buf); ++ buf);
    for (; isdigit (*buf); now = now * 10 + *buf - '0', ++ buf);
}

#define Max 1000020
int f[Max];

inline int max (int a, int b)
{
    return a > b ? a : b;
}

int Main ()
{
    fread (buf, 1, BUF, stdin);
    int N;
    read (N);
    register int i, j;
    int x, y;
    for (i = 1; i <= N; ++ i)
    {
        read (x), read (y);

        for (j = N; j >= x; -- j)
            f[j] = max (f[j], f[j - x] + y);    
    }
    printf ("%d", f[N]);    
    return 0;
}
int ZlycerQan = Main ();
int main (int argc, char *argv[]) {;}
原文地址:https://www.cnblogs.com/ZlycerQan/p/7367487.html