HDU-1493 QQpet exploratory park(概率dp)

本文介绍了一道关于QQ宠物探险公园的概率DP题目,通过动态规划算法求解宠物到达特定网格的概率。使用两维DP数组记录掷骰子次数与到达网格位置,最终输出每个重要网格被触达的概率。

HDU-1493 QQpet exploratory park
Time Limit: 1000 ms / Memory Limit: 32768 kb
Description
Today, more and more people begin to raise a QQpet. You can get a lot of pleasure from it, although it does not have a real life and it calls for huge patience to take care of it. There is a place called QQpet exploratory park in the world. Every week, you can get a chance to have a joy there for free. The whole park contains 61 grids in a line, numbered from 0 to 60. Ten of them are important grids which will touch off ( 引发 ) an incident when the pet stands on. They are 5, 12, 22, 29, 33, 38, 42, 46, 50 and 55. Your pet is standing on the gird of number 0 in the beginning. You can toss the die ( 掷骰子 ) 10 times. Each time, the pet goes ahead n steps which n is the number from the die ( n ∈{ 1, 2, …, 6 } ). If your RP is great enough( calls RPG for short ), you will get many surprises in the important grids, such as some yuanbao( the money in QQpet world ), an improvement of your pet’s ability, and the most attractive gift-package. Now, your task is to calculate the probability(概率) of touching each important grid.

Input
The first line of the input contains an integer t– determining the number of datasets. Then t lines follows. Each line contains 6 numbers pi, i ∈{ 1, 2, …, 6 }, indicating the probability of getting 1 to 6 after you toss the die every time . p1+ p2+ … + p6 = 1.

Output
For each test case, output the probability of touching each important grid. accurate up to 1 decimal places. There is a blank line between test cases. See the Sample Output to get the exactly output format.

Sample Input
2
0.000 1.000 0.000 0.000 0.000 0.000
0.500 0.000 0.000 0.000 0.000 0.500
Sample Output
5: 0.0%
12: 100.0%
22: 0.0%
29: 0.0%
33: 0.0%
38: 0.0%
42: 0.0%
46: 0.0%
50: 0.0%
55: 0.0%

5: 3.1%
12: 30.5%
22: 27.3%
29: 24.6%
33: 21.9%
38: 10.9%
42: 0.8%
46: 0.0%
50: 4.4%
55: 1.0%
Source
“2006校园文化活动月”之“校庆杯”大学生程序设计竞赛暨杭州电子科技大学第四届大学生程序设计竞赛

要明白DP中状态的含义,理解DP中的状态变得非常重要,这道概率DP,
用两维,第一维表示所有站点,第二维表示掷筛子10次,这样就能表示所有的状态,而且符合计算过程了。
dp[i][j]:第j次掷筛子刚好走到第i个站点的概率,dp[i][j]+=dp[i-k][j-1]*p[k] 1<=k<=6
设计的动态规划方程要能表示所有状态

#include<bits/stdc++.h>
using namespace std;
double dp[65][12];
double ans[15];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
       for(int i = 1;i <= 6;++i)
       {
           scanf("%lf",&ans[i]);
//           cout << ans[i] << endl;
       }
       memset(dp,0,sizeof(dp));
       for(int i = 1;i <= 6;++i)
            dp[i][1] = ans[i];
       for(int i = 2;i <= 10;++i)
       {
           for(int j = 0;j <= 60;++j)
           {
               for(int k = 1;k <= 6;++k)
               {
                   if(j >= k)
                      dp[j][i] += dp[j - k][i - 1] * ans[k];
               }
           }
       }
//       for(int i = 0;i <= 60;++i)
//       {
//           for(int j = 1;j <= 10;++j)
//           {
//               printf("%f ",dp[i][j]);
//           }
//           printf("\n");
//       }
        double ans = 0;
        for(int i = 1;i <= 10;++i)
            ans += dp[5][i];
        printf("5: %.1lf%%\n",ans * 100);
        ans = 0;
        for(int i = 1;i <= 10;++i)
            ans += dp[12][i];
        printf("12: %.1lf%%\n",ans * 100);
        ans = 0;
        for(int i = 1;i <= 10;++i)
            ans += dp[22][i];
        printf("22: %.1lf%%\n",ans * 100);
        ans = 0;
        for(int i = 1;i <= 10;++i)
            ans += dp[29][i];
        printf("29: %.1lf%%\n",ans * 100);
        ans = 0;
        for(int i = 1;i <= 10;++i)
            ans += dp[33][i];
        printf("33: %.1lf%%\n",ans * 100);
        ans = 0;
        for(int i = 1;i <= 10;++i)
            ans += dp[38][i];
        printf("38: %.1lf%%\n",ans * 100);
        ans = 0;
        for(int i = 1;i <= 10;++i)
            ans += dp[42][i];
        printf("42: %.1lf%%\n",ans * 100);
        ans = 0;
        for(int i = 1;i <= 10;++i)
            ans += dp[46][i];
        printf("46: %.1lf%%\n",ans * 100);
        ans = 0;
        for(int i = 1;i <= 10;++i)
            ans += dp[50][i];
        printf("50: %.1lf%%\n",ans * 100);
        ans = 0;
        for(int i = 1;i <= 10;++i)
            ans += dp[55][i];
        printf("55: %.1lf%%\n",ans * 100);
        if(t)
            printf("\n");
    }
    return 0;
}
dnSpy是目前业界广泛使用的一款.NET程序的反编译工具,支持32位和64位系统环境。它允许用户查看和编辑.NET汇编和反编译代码,以及调试.NET程序。该工具通常用于程序开发者在维护和调试过程中分析程序代码,尤其在源代码丢失或者无法获取的情况下,dnSpy能提供很大的帮助。 V6.1.8版本的dnSpy是在此系列软件更新迭代中的一个具体版本号,代表着该软件所具备的功能与性能已经达到了一个相对稳定的水平,对于处理.NET程序具有较高的可用性和稳定性。两个版本,即32位的dnSpy-net-win32和64位的dnSpy-net-win64,确保了不同操作系统架构的用户都能使用dnSpy进行软件分析。 32位的系统架构相较于64位,由于其地址空间的限制,只能支持最多4GB的内存空间使用,这在处理大型项目时可能会出现不足。而64位的系统能够支持更大的内存空间,使得在处理大型项目时更为方便。随着计算机硬件的发展,64位系统已经成为了主流,因此64位的dnSpy也更加受开发者欢迎。 压缩包文件名“dnSpy-net-win64.7z”和“dnSpy-net-win32.7z”中的“.7z”表示该压缩包采用了7-Zip压缩格式,它是一种开源的文件压缩软件,以其高压缩比著称。在实际使用dnSpy时,用户需要下载对应架构的压缩包进行解压安装,以确保软件能够正确运行在用户的操作系统上。 dnSpy工具V6.1.8版本的发布,对于.NET程序员而言,无论是32位系统还是64位系统用户,都是一个提升工作效率的好工具。用户可以根据自己计算机的操作系统架构,选择合适的版本进行下载使用。而对于希望进行深度分析.NET程序的开发者来说,这个工具更是不可或缺的利器。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值