AcWing 1226. 包子凑数
原题链接
中等
作者:
wjie
,
2020-07-04 23:51:02
,
所有人可见
,
阅读 881
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 105;
const int M = 1e4 + 5;
int arr[N], f[M];
int gcd(int a, int b)
{
if (a % b == 0)
return b;
return gcd(b, a%b);
}
int main()
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i)
scanf("%d", &arr[i]);
int tmp = arr[0];
for (int i = 1; i < n; ++i)
tmp = gcd(tmp, arr[i]);
if (tmp != 1)
{
puts("INF");
return 0;
}
f[0] = 1;
for (int i = 0; i < n; ++i)
{
for (int j = arr[i]; j < M; ++j)
{
f[j] = max(f[j], f[j-arr[i]]);
}
}
int res = 0;
for (int i = 1; i < M; ++i)
{
if (!f[i])
res++;
}
printf("%d", res);
return 0;
}