zoukankan      html  css  js  c++  java
  • Luogu 2737 [USACO4.1]麦香牛块Beef McNuggets

    NOIP2017 D1T1 的结论,两个数$a, b$所不能表示出的最大的数为$a * b - a - b$。

    听了好几遍证明我还是不会

    注意到本题中给出的数都非常小,所以最大不能表示出的数$leq 256 * 256 - 256 * 2 = 65024$。

    那么直接用这个$65024$作为背包容量跑完全背包就好了。

    时间复杂度$O(maxV * n)$。

    Code:

    #include <cstdio>
    using namespace std;
    
    const int N = 15;
    const int M = 65030;
    
    int n, a[N];
    bool f[M];
    
    inline void read(int &X) {
        X = 0; char ch = 0; int op = 1;
        for(; ch > '9'|| ch < '0'; ch = getchar())
            if(ch == '-') op = -1;
        for(; ch >= '0' && ch <= '9'; ch = getchar())
            X = (X << 3) + (X << 1) + ch - 48;
        X *= op;
    }
    
    int main() {
        read(n);
        for(int i = 1; i <= n; i++) read(a[i]);
        
        f[0] = 1;
        for(int i = 0; i < M; i++)
            for(int j = 1; j <= n; j++)
                if(i - a[j] >= 0) f[i] |= f[i - a[j]];
        
        int ans = 0;
        for(int i = 65029; i >= 0; i--)
            if(!f[i]) {
                ans = i;
                break;
            }
        if(ans > 65024) ans = 0;
        
        printf("%d
    ", ans);
        return 0;
    }
    View Code
  • 相关阅读:
    08-12 NOIP模拟测试18
    08-09 NOIP模拟测试15
    08-11 NOIP模拟测试17
    08-10 NOIP模拟测试16
    08-07 NOIP模拟测试14
    08-03 NOIP模拟测试12
    [SDOI2011]拦截导弹
    08-01 NOIP模拟测试11
    零散知识点
    07-29 NOIP模拟测试10
  • 原文地址:https://www.cnblogs.com/CzxingcHen/p/9571534.html
Copyright © 2011-2022 走看看