题目解法新颖,值得拓展思维。
优化:将被捕概率转换为安全概率,即将被捕概率小于P的限制条件转换为安全概率大于等于1-P
题解:dp[i]的值是抢了i价值的安全概率,从V(全部都抢的价值总和)开始从大到小地去dp。以最大地安全概率来更新dp[i],最后从V开始从大到小查询dp[v]从而得到满足要求的最大的v。
dp中的贪心思维体现在了最大的安全概率以及最后的查询顺序。

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+7;
double dp[N];
struct node {
   
	int w;
	double p;
}rec[N];
int main()
{
   
	int t,cnt=0;
	scanf("%d", &t);
	while(t--) {
   
		double P;
		int n,V=0;
		scanf("%lf%d",&P, &n);
		P=1-P;
		for(int i=1; i<=n; i++) {
   
			scanf("%d%lf", &rec[i].w, &rec[i].p);
			rec[i].p=1-rec[i].p,V+=rec[i].w;
		}
		memset(dp,0,sizeof(dp));
		dp[0]=1;
		for(int i=1; i<=n; i++) 
			for(int j=V; j>=rec[i].w; j--) {
   
				dp[j]=max(dp[j],dp[j-rec[i].w]*rec[i].p);
			}
		for(int i=V; i>=0; i--) {
   
			if(dp[i]>=P) {
   
				printf("Case %d: %d\n",++cnt,i);
				break;
			}
		}
	}
	return 0;
}