Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstring>
- #include <cassert>
- #include <algorithm>
- using namespace std;
- int n;
- int a[2010];
- int cnt[16];
- int main(int, char *args[])
- {
- #ifndef ONLINE_JUDGE
- freopen(args[1], "r", stdin);
- freopen(args[2], "w", stdout);
- #endif
- assert(scanf("%d", &n) == 1);
- assert(1 < n && n < 2011);
- memset(cnt, 0, sizeof cnt);
- for(int i = 0; i < n; i++)
- {
- assert(scanf("%d", &a[i]) == 1);
- assert(1 <= a[i] && a[i] <= 15);
- cnt[a[i]]++;
- }
- int all = 1 << 15;
- int best = n;
- for(int i = 0; i < all; i++)
- {
- bool ok = true;
- int cur = 0;
- for(int j = 0; j < 15; j++) if (!(i & (1 << j))) cur += cnt[j + 1];
- if (cur >= best) continue;
- for(int j = 0; j < 15; j++)
- if (cnt[j + 1])
- if (i & (1 << j))
- for(int k = j + 1; k < 15; k++)
- if (cnt[k + 1])
- if (i & (1 << k))
- if ((k + 1) % (j + 1) == 0) ok = false;
- if (ok) best = cur;
- }
- printf("%d\n", best);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement