标签:
Description
Input
Output
Sample Input
Sample Output
1 #include<stdio.h> 2 #include<algorithm> 3 #include<string.h> 4 using namespace std; 5 int val[200] ; 6 double cat[200] ; 7 double pro ; 8 int n ; 9 double dp[20000] ; 10 11 12 int main () { 13 // freopen ("a.txt" , "r" , stdin ) ; 14 int T ; 15 int sum ; 16 17 scanf ("%d" , &T ) ; 18 while (T-- ) { 19 scanf ("%lf%d" , &pro , &n) ; 20 sum = 0 ; 21 for (int i = 0 ; i < n ; i++ ) { 22 scanf ("%d%lf" , &val[i] , &cat[i]) ; 23 sum += val[i] ; 24 } 25 // printf ("sum=%d\n" , sum ) ; 26 27 memset (dp , 0 , sizeof(dp) ); 28 dp[0] = 1 ; 29 for (int i = 0 ; i < n ; i++ ) { 30 for (int j = sum ; j >= val[i] ; j-- ) { 31 dp[j] = max (dp[j] , dp[j - val[i]] * (1.0 - cat[i]) ) ; 32 33 } 34 35 } 36 37 for (int i = sum ; i >= 0 ; i-- ) { 38 if ( dp[i] > 1 - pro ) { 39 printf ("%d\n" , i ) ; 40 break ; 41 } 42 } 43 44 } 45 return 0; 46 }
标签:
原文地址:http://www.cnblogs.com/get-an-AC-everyday/p/4271031.html