在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
纯粹母函数+滚动数组,水之。 1 /* 2386 */ 2 #include <iostream> 3 #include <string> 4 #include <map> 5 #include <queue> 6 #include <set> 7 #include <stack> 8 #include <vector> 9 #include <algorithm> 10 #include <cstdio> 11 #include <cmath> 12 #include <ctime> 13 #include <cstring> 14 #include <climits> 15 #include <cctype> 16 using namespace std; 17 18 const int maxn = 20005; 19 20 int cnt[305]; 21 int score[305]; 22 bool f[2][maxn]; 23 24 int main() { 25 int i, j, k; 26 int t, tt; 27 int n, m; 28 int ans, mx; 29 int cur, pre; 30 31 #ifndef ONLINE_JUDGE 32 freopen("data.in", "r", stdin); 33 freopen("data.out", "w", stdout); 34 #endif 35 36 scanf("%d", &tt); 37 for (t=1; t<=tt; ++t) { 38 scanf("%d %d", &n, &m); 39 memset(cnt, 0, sizeof(cnt)); 40 mx = 0; 41 for (i=0; i<n; ++i) { 42 scanf("%d", &k); 43 mx = max(k, mx); 44 ++cnt[k]; 45 ++cnt[k<<1]; 46 ++cnt[(k<<1)+k]; 47 } 48 --cnt[(mx<<1)+mx]; 49 for (n=i=0; i<305; ++i) 50 if (cnt[i]) 51 score[n++] = i; 52 memset(f, false, sizeof(f)); 53 f[0][0] = f[1][0] = true; 54 55 for (j=1, cur=1, pre=0; j<=m; ++j, pre=cur, cur=!cur) { 56 for (i=0; i<=score[n-1]*j; ++i) { 57 for (k=0; k<n; ++k) { 58 if (f[pre][i] && i+score[k]<maxn) 59 f[cur][i+score[k]] = true; 60 } 61 } 62 } 63 ans = 0; 64 for (i=0; i<=score[n-1]*m; ++i) 65 if (f[pre][i]) 66 ++ans; 67 printf("Scenario #%d:\n%d\n\n", t, ans); 68 } 69 70 #ifndef ONLINE_JUDGE 71 printf("%d\n", (int)clock()); 72 #endif 73 74 return 0; 75 }
|
请发表评论