题目链接

详情见愿题目

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <bits/stdc++.h>
#define N 100005

using namespace std;

int n, a[N], maxx, ans, vis[25000], f[25000], t;

int main()
{
cin >> t;
while (t--)
{
maxx = ans = 0;
cin >> n;
for (int i = 1; i <= 25000; ++i)
vis[i] = 0;
for (int i = 1; i <= n; ++i)
{
cin >> a[i];
maxx = max(maxx, a[i]);
}
sort(a + 1, a + 1 + n);//先排序
for (int i = 1; i <= n; ++i)
{
if(vis[a[i]]) //标记过了,不选
continue;
ans++; vis[a[i]] = 1;
for (int k = a[i]; k <= maxx; ++k) //线性筛数
{
if(vis[k-a[i]])
vis[k] = 1;
}
}
cout << ans << endl;
}
}

评论