1 条题解

  • 2
    @ 2021-8-8 1:33:20

    C++ :

    #include<bits/stdc++.h>
    
    using namespace std;
    const int N = 105, M = 1e5 + 10;
    int g[M], a[N], c[N];
    bool f[M];
    int n, m;
    
    int main() {
        while (scanf("%d%d", &n, &m), n || m) {
            for (int i = 1; i <= n; i++)
                scanf("%d", &a[i]);
            for (int i = 1; i <= n; i++)
                scanf("%d", &c[i]);
            memset(f, 0, sizeof(f));
            f[0] = true;
            for (int i = 1; i <= n; i++) {
                memset(g, 0, sizeof(g));
                for (int j = a[i]; j <= m; j++) {
                    if (!f[j] && f[j - a[i]] && g[j - a[i]] < c[i])
                        f[j] = true, g[j] = g[j - a[i]] + 1;
                }
            }
            int res = 0;
            for (int i = 1; i <= m; i++)if (f[i])res++;
            printf("%d\n", res);
        }
        return 0;
    }
    
    • 1

    信息

    ID
    192
    时间
    1000ms
    内存
    128MiB
    难度
    7
    标签
    递交数
    18
    已通过
    10
    上传者