GPA
Time limit (normal/java): 1000ms/3000ms Run memory limit: 65536KByte
Total Submissions: 171 tested by: 40
Title Description
For some elite schools, the institute can not only be pushed off by the school, but also by the students themselves to the School of Hope GPA application, the process is somewhat similar to the foreign students to the school to submit resumes waiting for offer process. However, the delivery of the application needs to go to the corresponding school admissions submit materials, which requires some costs (such as tolls, etc.), and each institution has its own success rate of admission. Now, if the total cost does not exceed the limit, find the maximum success rate.
Input
The input contains multiple lines.
The first line contains two positive integers c and N, representing the cost limit and N schools.
Next n rows, each row contains a positive integer c and a floating-point fractional W, respectively, indicating the cost and success rate of the material to be delivered to the school.
Output
Output only one row of results, including a decimal point that retains a 4-bit fractional fraction (with%), indicating the maximum success rate.
Sample input
10 3
4 0.1
4 0.2
5 0.3
Sample output
44%
Title Link: http://acm.njupt.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1860
Title Analysis: 0/1 knapsack problem + probability of the problem, the probability of pre-processing, get the probability of not passing, because the situation is more difficult to calculate, and then the bare 0/1 backpack.
DP[J] Indicates the minimum failure rate when the backpack capacity is J, because the backpack is not required to be filled so the initialization is all 1
#include <cstdio> #include <cstring> #include <algorithm>using namespace std;int const MAX = 10005;int W [MAX];d ouble R[max], Dp[max];int main () { int c, n; scanf ("%d%d", &c, &n); for (int i = 0; i < n; i++) { scanf ("%d%lf", &w[i], &r[i]); R[i] = 1.0-r[i]; } for (int i = 0; I <= C; i++) dp[i] = 1.0; for (int i = 0; i < n; i++) for (int j = c; j >= W[i]; j--) dp[j] = min (Dp[j], dp[j-w[i]] * r[i]); Double ans = (1.0-dp[c]) * 100.0; printf ("%.4f%%\n", ans);}
Noj 1860 Protection (0/1 backpack probability DP)