Untitled
unknown
plain_text
a year ago
893 B
2
Indexable
Never
#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<cstdio> #include<algorithm> using namespace std; int a[105], ans[105]; int n, t, flag; int cnt; bool cmp(int x, int y) { return x > y; } void dfs(int sum, int start) { if (sum > t) return; if (sum == t) { cnt++; flag = 1; return; } for (int i = start; i < n; i++) { if (start == i || a[i - 1] != a[i]) { dfs(sum + a[i], i + 1); } } } int main() { // freopen("input.txt", "r", stdin); int suml; int T; cin >> T; for (int tc = 1; tc <= T; tc++) { cnt = 0; cin >> t >> n; suml = 0; flag = 0; for (int i = 0; i < n; i++) { cin >> a[i]; suml += a[i]; } cout << "#" << tc << " "; if (suml < t) { cout << -1 << endl; continue; } sort(a, a + n, cmp); dfs(0, 0); if (!flag) cout << -1 << endl; cout << cnt << endl; } }