标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 18287 Accepted Submission(s): 7320
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <cmath> using namespace std; int n,m; const int N = 1E4+5; int a[N]; double b[N],dp[N]; double ans,mmax; void solve(int cost,double value) { for ( int i = n ; i >= cost ; i-- ) dp[i] = min(dp[i],dp[i-cost]*value); } void init() { for ( int i = 0 ; i <N ; i++ ) dp[i]=1.0; mmax=-1; ans=1; // memset(a,0,sizeof(a)); // memset(b,0,sizeof(b)); } int main() { while (scanf("%d %d",&n,&m)!=EOF) { init(); if ( (n==0)&&(m==0) ) break; for ( int i = 1 ; i <= m ; i++ ) scanf("%d %lf",&a[i],&b[i]); for ( int i = 1 ; i <= m ; i++ ) b[i]=1-b[i]; if ( n==0 ) { for ( int i = 1 ; i <= m ; i++ ) if ( a[i]==0 ) ans = ans*b[i]; printf("%.1lf%%\n",(1-ans)*100); continue; } for ( int i = 1 ; i <= m ; i++ ) solve(a[i],b[i]); ans = 1-dp[n]; ans = ans*100; // for ( int i = 1 ; i <= n ; i++ ) // printf("%lf ",dp[i]); printf("%.1lf%%\n",ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/111qqz/p/4392830.html