1 /*
2 Author: Leo.W
3 Descriptipn:典型的01背包問題,對輸入的每組數據【花費及可能性】進行背包判斷,
4 得到在花費總和是經濟能力范圍內的累計獲offer幾率最大的組合。
5 How to Do:f[V]=max{f[V],f[V-c[i]]+w[i]};
6 【前后f[V]分別表示前i個大學申請在總花費為V時的最大幾率和前i-1個大學申請在總花費為V時的最大幾率;
7 f[V-c[i]]表示前i-1個大學在總花費為V-c[i]時的最大幾率,
8 c[i]表示第i個大學申請的花費,w[i]則表示第i個大學申請成功的幾率】
9 */
10 #include <iostream>
11 #include <string.h>
12 using namespace std;
13 double f[100010];
14 int c[1010];
15 double w[1010];
16 int main(){
17 //freopen("in.txt","r",stdin);
18 int n,m;
19 int i,j;
20 while(scanf("%d%d",&n,&m),m||n){
21 for(i=0;i<m;i++){
22 scanf("%d%lf",&c[i],&w[i]);
23 }
24 memset(f,0.0,sizeof(f));
25 for(i=0;i<m;i++){
26 for(j=n;j>=c[i];j--){//比較是鑒于概率論的知識
27 f[j]=f[j]>(1-(1-f[j-c[i]])*(1-w[i]))?f[j]:(1-(1-f[j-c[i]])*(1-w[i]));
28 }
29 }
30 double sum=f[n]*100;
31 printf("%.1lf%%\n",sum);
32 }
33 return 0;
34 }
35
posted on 2012-03-02 23:59
Leo.W 閱讀(257)
評論(0) 編輯 收藏 引用