题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1203
题意:
该题要求得到一份offer的最大概率,在例子中的0.44 = 1-(1-0.2)*(1-0.3)这样求得。
状态方程则为:max[j]=max{max[j],1-(1-max[j-mon[i]])*(1-pop[i])};
Sample Input 10 3 4 0.1 4 0.2 5 0.3 0 0 Sample Output 44.0% Hint You should use printf("%%") to print a '%'.
************************************************
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<queue> #include<algorithm> #include<cmath> #include<iostream> using namespace std; typedef long long LL; #define INF 0x3f3f3f3f #define N 22000 #define MAXN 100000000 #define mod 1000000007 double dp[N],g[N]; int p[N]; int main() { int n,m,i,j; while(scanf("%d %d", &n,&m),n+m) { memset(dp,0,sizeof(dp)); memset(p,0,sizeof(p)); memset(g,0,sizeof(g)); for(i=1;i<=m;i++) scanf("%d %lf", &p[i], &g[i]); for(i=1;i<=m;i++) for(j=n;j>=p[i];j--) dp[j]=max(dp[j],1-(1-dp[j-p[i]])*(1-g[i])); printf("%.1f%%\n", dp[n]*100); } return 0; }