Collecting Bugs(概率dp)


题意:

需要查n个bug,每天查一个bug。有s个子系统,要求每个子系统至少有1个bug的期望

思路:

每次找到一个bug会有四种情况:

属于已经找到过的bug,和已出现过的子系统;

属于未经找到过的bug,和已出现过的子系统;

属于已找到过的bug,和未出现过的子系统;

属于未找到过的bug,和未现过的子系统;

dp[i][j] = p1 * (dp[i+1][j+1] + 1) + p2 * (dp[i+1][j] + 1) + p3 * (dp[i][j+1] + 1) + p4 * (dp[i][j]+1)
+1表示找到的bug,移项后即:
dp[i][j]=(dp[i+1][j]*p1+dp[i][j+1]*p2+dp[i+1][j+1]*p3+1.0)/(1.0-p4);
最后所得dp[0][0]即为所求(p1,p2,p34,p4个人定义)

代码:

#include<stdio.h>
#include<string.h>
#define N 1010
double dp[N][N];
double p1,p2,p3,p4;
int main()
{
    int n,s;
    while(~scanf("%d%d",&n,&s)){
        memset(dp,0,sizeof(dp));
        for(int i=n;i>=0;i--)
        for(int j=s;j>=0;j--){
            if(i==n&&j==s) continue;
            p1=1.0*(n-i)*j/(n*s);
            p2=1.0*i*(s-j)/(n*s);
            p3=1.0*(n-i)*(s-j)/(n*s);
            p4=1.0*i*j/(n*s);
            dp[i][j]=(dp[i+1][j]*p1+dp[i][j+1]*p2+dp[i+1][j+1]*p3+1.0)/(1.0-p4);
        }
        printf("%.4f\n",dp[0][0]);
    }
    return 0;
}
s is a fascinating hobby for many people, particularly those interested in studying insects and their behavior. However, it's crucial to follow ethical and legal guidelines, and to ensure that bugs are collected and handled humanely. Here are some tips for collecting bugs: 1. Check local regulations: Before you start collecting bugs, check your local regulations to make sure it is legal to do so. Some areas may have restrictions on collecting certain species or collecting bugs in protected areas. 2. Use ethical and humane methods: It's important to use ethical and humane methods when collecting bugs. Avoid using harmful chemicals, and instead use gentle methods such as nets or traps. Handle the bugs carefully and avoid injuring them. 3. Respect the environment: When collecting bugs, make sure to respect the environment and the other creatures that live there. Avoid damaging plants or other habitats, and leave the area as you found it. 4. Keep accurate records: Keep accurate records of the species you collect, when and where you collected them, and any other relevant information. This can be helpful for scientific research and for tracking changes in insect populations over time. 5. Release the bugs: After you have collected and observed the bugs, release them back into their natural habitat. Make sure to do so in a safe and appropriate location, and handle them carefully to avoid injury. Remember that collecting bugs can be a fun and educational hobby, but it's important to do so responsibly and ethically. By following these guidelines, you can enjoy the hobby while also helping to protect these fascinating creatures and their habitats.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值