【HDOJ】2386 Dart Challenge

时间:2023-03-09 13:30:40
【HDOJ】2386 Dart Challenge

纯粹母函数+滚动数组,水之。

 /* 2386 */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
using namespace std; const int maxn = ; int cnt[];
int score[];
bool f[][maxn]; int main() {
int i, j, k;
int t, tt;
int n, m;
int ans, mx;
int cur, pre; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif scanf("%d", &tt);
for (t=; t<=tt; ++t) {
scanf("%d %d", &n, &m);
memset(cnt, , sizeof(cnt));
mx = ;
for (i=; i<n; ++i) {
scanf("%d", &k);
mx = max(k, mx);
++cnt[k];
++cnt[k<<];
++cnt[(k<<)+k];
}
--cnt[(mx<<)+mx];
for (n=i=; i<; ++i)
if (cnt[i])
score[n++] = i;
memset(f, false, sizeof(f));
f[][] = f[][] = true; for (j=, cur=, pre=; j<=m; ++j, pre=cur, cur=!cur) {
for (i=; i<=score[n-]*j; ++i) {
for (k=; k<n; ++k) {
if (f[pre][i] && i+score[k]<maxn)
f[cur][i+score[k]] = true;
}
}
}
ans = ;
for (i=; i<=score[n-]*m; ++i)
if (f[pre][i])
++ans;
printf("Scenario #%d:\n%d\n\n", t, ans);
} #ifndef ONLINE_JUDGE
printf("%d\n", (int)clock());
#endif return ;
}