其他分享
首页 > 其他分享> > P5020 [NOIP2018 提高组] 货币系统

P5020 [NOIP2018 提高组] 货币系统

作者:互联网

Problem

自行阅读P5020 货币系统

Solution

不难发现就是去掉可以用别的货币表示的货币。

# include <bits/stdc++.h>
using namespace std;
const int N = 105;
int T;
int n,a[N];
int can[25005];
int main(void)
{
    scanf("%d",&T);
    while(T--)  
    {
        scanf("%d",&n);
        for(int i = 1; i <= n; i++)
        {
            scanf("%d",&a[i]);
            can[a[i]] = 1;
        }
        int m = 0;
        for(int i = 1; i <= n; i++) m = max(m,a[i]);
        for(int i = 1; i <= m; i++)
        {
            if(can[i])
            {
                for(int j = 1; j <= n; j++) if(i + a[j] <= m) can[i + a[j]] = 2;
            }
        }
        int total = 0;
        for(int i = 1; i <= n; i++) if(can[a[i]] == 2) ++total;
        printf("%d\n",n - total);
        for(int i = 1; i <= m; i++) can[i] = 0;
    }
    return 0;
}

标签:const,int,scanf,namespace,NOIP2018,货币,P5020
来源: https://www.cnblogs.com/luyiming123blog/p/15001123.html