I need A offer! (HDU 1203 01 backpack)

Source: Internet
Author: User

I need A offer!Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 18054 Accepted Submission (s): 7237


Problem descriptionspeakless very early want to go abroad, now he has finished all the required examinations, prepared all the materials to prepare, so, they need to apply for school. To apply for any university abroad, you have to pay a certain amount of application fees, which is very alarming. Speakless didn't have much money, only a total of n million dollars. He will choose a number of M schools (certainly within his financial range). Each school has a different application fee of a (million dollars), and speakless estimates the likelihood of his getting a offer from this school B. Whether or not there is an offer between different schools will not affect each other. "I need a offer," he shouted. Help the poor man, help him calculate the maximum probability that he can receive at least one offer. (if Speakless chooses more than one school, get an offer from any school).

Input has several sets of data, and the first row of each group of data has two positive integers n,m (0<=n<=10000,0<=m<=10000)
In the following M-line, each row has two data ai (integer), and Bi (real) represents the application fee for the I-school and the probability of getting an offer.
The last entry has two 0.

Output each set of data corresponds to an export, indicating the maximum probability that speakless may get at least one offer. Expressed as a percentage, accurate to one decimal place.

Sample Input
10 34 0.14 0.25 0.30 0

Sample Output
44.0%HintYou should use printf ("percent") to print a '% '.

Authorspeakless
Sourcegardon-dygg Contest 2
recommendjgshining | We have carefully selected several similar problems for you:2159 1114 1231 1257 2191 Test Instructions: There are n million in hand, here is the M school, want to use the N million newspaper school to get an offer, M schools have an application fee and the probability of getting an offer, and ask at least the maximum probability of getting one. Idea: First explain the sample: a total of 100,000 yuan, 3 schools (here is the number of a), the most likely to get the offer probability of the situation is: the school 2 and 3, only to get the school 1, only to get the school 3 offer, the two schools have received, and =0.2* (1-0.3) + (1-0.2) *0.3+0.2*0.3=0.44. But if this is a hassle, we can turn into the smallest probability that an offer is not available, then the answer is 1-the minimum probability, which translates into 01 knapsack problems. Code:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < cmath> #include <string> #include <map> #include <stack> #include <vector> #include <set > #include <queue> #pragma comment (linker, "/stack:102400000,102400000") #define MAXN 10005#define MAXN 2005# Define mod 1000000009#define INF 0x3f3f3f3f#define pi ACOs ( -1.0) #define EPS 1e-6#define Lson rt<<1,l,mid#define RSO N rt<<1|1,mid+1,r#define FRE (i,a,b) for (i = A, I <= b; i++) #define FRL (i,a,b) for (i = A; I < b; i++) #define Mem (T, v) memset ((t), V, sizeof (t)) #define SF (n) scanf ("%d", &n) #define SFF (A, b) scanf ("%d%d", &a, & AMP;B) #define SFFF (a,b,c) scanf ("%d%d%d", &a, &b, &c) #define PF printf#define DBG pf ("hi\n" typedef long Long ll;using namespace Std;//dp[i] represents the minimum probability that cost I million to get an offer double dp[maxn],p[maxn];int n,m;int w[maxn];int    Main () {int i,j; while (SFF (n,m)) {if (n==0&&m==0) break;            FRE (i,1,m) {scanf ("%d%lf", &w[i],&p[i]);  P[i]=1.0-p[i];        Not get the probability} FRL (i,0,n+1)//initialized to 1.0 dp[i]=1.0;        FRE (i,1,m) {for (j=n;j>=w[i];j--) dp[j]=min (Dp[j],dp[j-w[i]]*p[i]);   } PF ("%.1lf%%\n", (1-dp[n]) *100); Then the maximum probability is 1-dp[n] return 0;}




I need A offer! (HDU 1203 01 backpack)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.