提交时间:2024-05-12 06:45:03

运行 ID: 146500

#include <iostream> #include <algorithm> #include <cstring> using namespace std; const int N = 110, M = 25000 + 10; int T, n; int v[101]; bool f[25001]; int main() { cin >> T; while (T--) { cin >> n; for (int i = 1; i <= n; i++) cin >> v[i]; sort(v + 1, v + 1 + n); int res = 0; //f[0] = true; for (int i = 1; i <= n; i++) { if (f[v[i]]==0) { res++; f[v[i]] = 1; for(int j = v[i];j <= v[n];j++){ if(f[j-v[i]]==1){ f[j] = 1; } } } } cout << res << endl; memset(v, 0, sizeof v); memset(f, false, sizeof f); } return 0; }