标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 1587 Accepted Submission(s): 566
#include <cstdio> #include <iostream> #include <sstream> #include <cmath> #include <cstring> #include <cstdlib> #include <string> #include <vector> #include <map> #include <set> #include <queue> #include <stack> #include <algorithm> using namespace std; #define ll long long #define _cle(m, a) memset(m, a, sizeof(m)) #define repu(i, a, b) for(int i = a; i < b; i++) #define repd(i, a, b) for(int i = b; i >= a; i--) #define sfi(n) scanf("%d", &n) #define pfi(n) printf("%d\n", n) #define pfl(n) printf("%I64d\n", n) #define MAXN 600000 ll d[MAXN]; ll sum; int s[45]; int n; double p; double mm[45]; void get_m() { mm[0] = 1.0; repu(i, 1, 45) mm[i] = 2.0 * mm[i - 1]; return ; } void dp() { memset(d, 0, sizeof(d)); d[0] = 1; for(int i = 1; i <= n; i++) for(int j = sum; j >= s[i]; j--) d[j] = d[j]+d[j-s[i]]; return ; } int main() { int T; sfi(T); get_m(); while(T--) { sfi(n); scanf("%lf", &p); sum = 0; repu(i, 1, n + 1) { sfi(s[i]); sum += s[i];} dp(); double num = 0.0; double monkey = (p * mm[n]); for(ll i = 0; i <= sum; i++) { num += d[i]; if(num >= monkey) { printf("%I64d\n", i); break; } } } return 0; }
标签:
原文地址:http://www.cnblogs.com/sunus/p/4741282.html