N0lP 2018 monetary system

Synchronization: buringstraw.win/archives/59/

N0lP 2018 monetary system

Paddle week wrote this stuff?

topic

Portal

Currency species \ (n-\) , the denomination of the array \ (a [1..n] \) of the money system referred to as \ ((n-, A) \) .

Two money system $ (n, a) $ and $ (m, B) \ (are equivalent if and only if for any non-negative integer \) X $, it can be either system are Expressed two currencies or any one of them can not be Expressed.

Find a currency \ ((m, b) \ ) , satisfies \ ((m, b) \ ) with the original currency \ ((n, a) \ ) equivalent, and \ (m \) possible small.

The minimum output \ (m \)

solution

If a monetary system where money can be certain other currencies, then you can kick off.

Therefore, the first sort, then each a[i]can be expressed, it is marked,

Reuse thought to backpack full screen (to be full of money mark)

Code

#include <cstdio>
#include <algorithm>

using std::max;
using std::sort;

const int MAXN = 105, MAXA = 25000;

int main (void) {
    int T;
    scanf("%d", &T);
    while (T--) {
        int a[MAXN] = {0};
        bool v[MAXA] = {0};
        int n, maxa = 0, ans = 0;
        scanf("%d", &n);
        for (int i = 1; i <= n; ++i) {
            scanf("%d", a + i);
            maxa = max(maxa, a[i]);
        }
        sort(a + 1, a + 1 + n);
        for (int i = 1; i <= n; ++i) {
            if (v[a[i]]) continue;
            ++ans;
            v[a[i]] = 1;
            for (int j = a[i]; j <= maxa; ++j) {
                if (v[j - a[i]]) v[j] = 1;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/buringstraw/p/11608993.html