标签:
http://acm.hdu.edu.cn/showproblem.php?pid=4815
Description
Input
Output
Sample Input
Sample Output
#include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> #include<algorithm> using namespace std; const int N = 50; const int M = 40010; int a[N]; double dp[N][M]; int main() { int t, n; double p; scanf("%d", &t); while(t--) { scanf("%d%lf", &n, &p); for(int i = 0 ; i < n ; i++) scanf("%d", &a[i]); memset(dp, 0, sizeof(dp)); dp[0][0] = 1;//写0道题得0分的概率为1 for(int i = 0 ; i < n ; i++) { for(int j = 0 ; j < n * 1000 ; j++) { dp[i + 1][j] += dp[i][j] * 0.5;//第i+1道题没有写对,没有拿到这道题的分 dp[i + 1][j + a[i]] += dp[i][j] * 0.5;//第i+1道题写对了,拿到了这道题的分 } } double x = 0; int m = 0; for(int j = n * 1000 ; j >= 0 ; j--) { x += dp[n][j];//写n道题各个得分的概率和 if(x > 1 - p) { m = j; break; } } printf("%d\n", m); } return 0; }
hdu 4815 Little Tiger vs. Deep Monkey(01背包)
标签:
原文地址:http://www.cnblogs.com/qq2424260747/p/4867220.html