QQpet exploratory park(DP)

QQpet exploratory park

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.

InputThe first line of the input contains an integer t?C 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. 
OutputFor 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%

//题意:第一行测试组数 T ,然后给出掷骰子出现 1 2 3 4 5 6 的概率,问到达指定位置的概率是多少?简单概率dp

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 using namespace std;
 5
 6 double dp[20][100]; // i 次到 j 的概率
 7 double p[10];
 8 double a[10];
 9
10 int main()
11 {
12     int T;
13     cin>>T;
14     while (T--)
15     {
16         for (int i=1;i<=6;i++)
17             scanf("%lf",&p[i]);
18         memset(dp,0,sizeof(dp));
19         memset(a,0,sizeof(a));
20         for (int i=1;i<=6;i++) dp[1][i]=p[i];
21         for (int i=2;i<=10;i++)
22         {
23             for (int j=0;j<=60;j++)
24             {
25                 for (int k=1;k<=6;k++)
26                     if (j-k>=0)
27                         dp[i][j]+=dp[i-1][j-k]*p[k];
28             }
29         }
30         for(int i=10;i>0;i--)    a[0]+=dp[i][5];  printf("5: %.1lf%%\n",a[0]*100);
31         for(int i=10;i>0;i--)    a[1]+=dp[i][12]; printf("12: %.1lf%%\n",a[1]*100);
32         for(int i=10;i>0;i--)    a[2]+=dp[i][22]; printf("22: %.1lf%%\n",a[2]*100);
33         for(int i=10;i>0;i--)    a[3]+=dp[i][29]; printf("29: %.1lf%%\n",a[3]*100);
34         for(int i=10;i>0;i--)    a[4]+=dp[i][33]; printf("33: %.1lf%%\n",a[4]*100);
35         for(int i=10;i>0;i--)    a[5]+=dp[i][38]; printf("38: %.1lf%%\n",a[5]*100);
36         for(int i=10;i>0;i--)    a[6]+=dp[i][42]; printf("42: %.1lf%%\n",a[6]*100);
37         for(int i=10;i>0;i--)    a[7]+=dp[i][46]; printf("46: %.1lf%%\n",a[7]*100);
38         for(int i=10;i>0;i--)    a[8]+=dp[i][50]; printf("50: %.1lf%%\n",a[8]*100);
39         for(int i=10;i>0;i--)    a[9]+=dp[i][55]; printf("55: %.1lf%%\n",a[9]*100);
40         if (T) cout<<endl;
41     }
42     return 0;
43 }

				
时间: 2024-10-08 01:29:04

QQpet exploratory park(DP)的相关文章

【HDOJ】1493 QQpet exploratory park

超水的动态规划.最后要对概率求Sigma. 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 5 #define MAXN 61 6 #define MAXK 11 7 8 double dp[MAXK][MAXN]; 9 double a[7]; 10 int b[10] = {5, 12, 22, 29, 33, 38, 42, 46, 50, 55}; 11 12 int main()

!HDU 1493 QQpet exploratory park-dp

题意:有61个编号从0到60的站点,其中有几个里面有宝藏,通过掷筛子的方式决定每次前进几步,只能掷10次筛子,求能走到各个有宝藏的站点的概率 分析: 刚开始又习惯性的想着以每个站点为状态,写了代码出来样例错了,后来想到代码里没有管筛子只能用10次的事情.画出样例的计算过程图,发现用站点作为状态不行,因为在不同的步骤里站点会有不同的概率,不能用前面的站点的总概率来求后面站点的概率,想明白后:用两维,第一维表示所有站点,第二维表示掷筛子10次,这样就能表示所有的状态,而且符合计算过程了. dp[i]

Codeforces 526B Om Nom and Dark Park 树形dp

题意:给你一颗完全二叉树,每条边有一个值,可以对这个值进行加操作,让你满足根节点到所有叶子节点路径值相同  ,问你最少要加多少值. 解题思路:从上往下树形DP,位运算会比较方便. 解题代码: 1 // File Name: b.cpp 2 // Author: darkdream 3 // Created Time: 2015年04月05日 星期日 00时47分32秒 4 5 #include<vector> 6 #include<list> 7 #include<map&g

[CSP-S模拟测试]:Park(树上DP)

题目描述 公园里有$n$个雕像,有$n-1$条道路分别连接其中两个雕像,任意两个雕像可以直接或间接相连.现在每个景点$i$聚集着$P_i$只鸽子,旅行家手里有$v$数量的面包屑. 一旦旅行家在雕像$i$撒下$1$单位面包屑,那么相邻的雕像的鸽子就都会飞到雕像$i$来觅食. 时间线是这样的:首先,旅行家到达雕像$i$并与$P_i$鸽子会面.然后,他放下$1$单位面包屑.他离开雕像.在旅行家到达下一座雕像之前,来自相邻雕像的鸽子移动到雕像$i$(所以这些鸽子不计入他遇到的鸽子数).注意旅行家每到一达

[入门向选讲] 插头DP:从零概念到入门 (例题:HDU1693 COGS1283 BZOJ2310 BZOJ2331)

转载请注明原文地址:http://www.cnblogs.com/LadyLex/p/7326874.html 最近搞了一下插头DP的基础知识……这真的是一种很锻炼人的题型…… 每一道题的状态都不一样,并且有不少的分类讨论,让插头DP十分锻炼思维的全面性和严谨性. 下面我们一起来学习插头DP的内容吧! 插头DP主要用来处理一系列基于连通性状态压缩的动态规划问题,处理的具体问题有很多种,并且一般数据规模较小. 由于棋盘有很特殊的结构,使得它可以与“连通性”有很强的联系,因此插头DP最常见的应用要数

【POJ 2750】 Potted Flower(线段树套dp)

[POJ 2750] Potted Flower(线段树套dp) Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4566   Accepted: 1739 Description The little cat takes over the management of a new park. There is a large circular statue in the center of the park, surrou

ZeptoLab Code Rush 2015 B. Om Nom and Dark Park DFS

B. Om Nom and Dark Park Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/526/problem/B Description Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living a

DP计数(UVA 885&amp;&amp;POJ 2704)

Pascal's Travels Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5258   Accepted: 2363 Description An n x n game board is populated with integers, one nonnegative integer per square. The goal is to travel along any legitimate path from t

【BZOJ2310】ParkII 插头DP

[BZOJ2310]ParkII Description Hnoi2007-Day1有一道题目 Park:给你一个 m * n 的矩阵,每个矩阵内有个权值V(i,j) (可能为负数),要求找一条回路,使得每个点最多经过一次,并且经过的点权值之和最大,想必大家印象深刻吧. 无聊的小 C 同学把这个问题稍微改了一下:要求找一条路径,使得每个点最多经过一次,并且点权值之和最大,如果你跟小 C 一样无聊,就麻烦做一下这个题目吧. Input 第一行 m, n,接下来 m行每行 n 个数即. V( i,j