BNU29140 Taikotaiko(概率)

BNU29140——Taiko taiko——————【概率题、规律题】

Taiko taiko

Time Limit: 1000ms
Memory Limit: 65536KB
64-bit integer IO format:  %lld      Java class name: Main
Prev 
Submit  Status  Statistics  Discuss
  Next
Type: 
None
 
  None   Graph Theory       2-SAT       Articulation/Bridge/Biconnected Component       Cycles/Topological Sorting/Strongly Connected Component       Shortest Path           Bellman Ford           Dijkstra/Floyd Warshall       Euler Trail/Circuit       Heavy-Light Decomposition       Minimum Spanning Tree       Stable Marriage Problem       Trees       Directed Minimum Spanning Tree       Flow/Matching           Graph Matching               Bipartite Matching               Hopcroft–Karp Bipartite Matching               Weighted Bipartite Matching/Hungarian Algorithm           Flow               Max Flow/Min Cut               Min Cost Max Flow   DFS-like       Backtracking with Pruning/Branch and Bound       Basic Recursion       IDA* Search       Parsing/Grammar       Breadth First Search/Depth First Search       Advanced Search Techniques           Binary Search/Bisection           Ternary Search   Geometry       Basic Geometry       Computational Geometry       Convex Hull       Pick's Theorem   Game Theory       Green Hackenbush/Colon Principle/Fusion Principle       Nim       Sprague-Grundy Number   Matrix       Gaussian Elimination       Matrix Exponentiation   Data Structures       Basic Data Structures       Binary Indexed Tree       Binary Search Tree       Hashing       Orthogonal Range Search       Range Minimum Query/Lowest Common Ancestor       Segment Tree/Interval Tree       Trie Tree       Sorting       Disjoint Set   String       Aho Corasick       Knuth-Morris-Pratt       Suffix Array/Suffix Tree   Math       Basic Math       Big Integer Arithmetic       Number Theory           Chinese Remainder Theorem           Extended Euclid           Inclusion/Exclusion           Modular Arithmetic       Combinatorics           Group Theory/Burnside's lemma           Counting       Probability/Expected Value   Others       Tricky       Hardest       Unusual       Brute Force       Implementation       Constructive Algorithms       Two Pointer       Bitmask       Beginner       Discrete Logarithm/Shank's Baby-step Giant-step Algorithm       Greedy       Divide and Conquer   Dynamic Programming                    Tag it!

拆拆超级喜欢太鼓达人(赛后大家可自行百度规则),玩久了也对积分规则产生了兴趣,理论上连击数越多,分数增加的越快,而且还配合着击打准确度有相应的计算规则,拆拆觉得这些规则太复杂了,于是把规则自行简化了下:

对于一段击打序列,我们假设Y为打中,N为未打中 (没有良可之分了)

我们视连续的n次击中为n连击  相应的分数为 1+2+3+。。。+n

例如序列YNNYYYNYN的总分数为1+1+2+3+1=8

当然 击中是有概率的 我们假定概率始终为P(0<=P<=1)拆拆的击中概率很高的恩恩=w=

于是现在拆拆想知道对于长度为L的序列  击中概率为P时 获得积分的期望是多少

 

Input

一个整数T(表示T组数据)

接下来的T组数据

接下来T行 每行一个整数L 一个浮点数P

数据范围

1<=T<=1000

1<=L<=1000

0<=P<=1

 

Output

对于每组数据输出一行1个6位小数 即题目描述的期望

 

Sample Input

2
2 0.9
3 0.5

Sample Output

2.610000
2.125000

思路:应小妹的要求 讲清楚不装b

1 1*p+0*0.1(Y N)

2 3*p*p+1*p(1-p)+1*(1-p)*p+0(YY YN NY NN)== P^2+2*p

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
double dp[1005];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        double p;
        scanf("%d%lf",&n,&p);
//        printf("%lf%d")
        memset(dp,0,sizeof(dp));

        dp[1]=1.0*p;

        for(int i=2;i<=n;i++)
        dp[i]=(dp[i-1]+i)*p;

        printf("%.6lf\n",dp[n]);
    }
}



你可能感兴趣的:(算法,数学)