UVA 11176 Winning Streak

#include <iostream>
#include <stdio.h>
#include <cstring>
#define N 501

using namespace std;
int n;
double p;
double pa[N][N];
double pow[N];
void Init()
{
    memset(pa,0,sizeof(pa));
    pow[0]=1;
    for(int i=1;i<N;i++)
    {
        pow[i] = pow[i-1]*p;
    }
}

void Do()
{
    for(int i=0;i<=n;i++)
    {
        for(int j=0; j<=n; j++)
        {
            if(i-j<=0)
                pa[i][j] = 1;
            else if(i-j-1==0)
                pa[i][j]=pa[i-1][j]-pow[j+1];
            else if(i-j-2>=0)
                pa[i][j]=pa[i-1][j]-pa[i-j-2][j]*(1-p)*pow[j+1];
        }
    }

    double ans = 0;
    for(int i=1;i<=n;i++)
    {
        ans += (pa[n][i]-pa[n][i-1])*i;
    }
    printf("%.6lf\n",ans);
}

int main()
{
    while(scanf("%d %lf",&n,&p)!=EOF && n)
    {
        Init();

        Do();
    }
    return 0;
}
时间: 2024-10-17 10:40:55

UVA 11176 Winning Streak的相关文章

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

UVA, 10684 The jackpot

题意:首先输入一个N,代表后面N个继续输入的数字,求数字的最大子序列和 思路:动态规划,最大子序列和(最大子段和) 最大子序列和的转移方程:f[i]=max(f[i-1]+date[i],date[i])可以直接用…… 代码如下: 1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 5 using namespace std; 6 7 int n,date[10000],f[10000];

maximum sum

uva,10684 1 #include <iostream> 2 #include <cstdio> 3 #define maxn 10005 4 using namespace std; 5 6 int main() 7 { 8 int n; 9 int a[maxn]; 10 while(scanf("%d",&n),n) 11 { 12 for(int i=0;i<n;i++) 13 scanf("%d",&a[

《算法竞赛入门经典——训练指南》第二章题库

UVa特别题库 UVa网站专门为本书设立的分类题库配合,方便读者提交: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=442 注意,下面注有"extra"的习题并没有在书中出现,但在上面的特别题库中有,属于附加习题. 基础练习 (Basic Problems) UVa11388 GCD LCM UVa11889 Benefit UVa10943 How do y

belt filter press for saLe

After a perfect inning from Farnsworth in the eighth, the Yankees would have Alex Rodriguez coming to the plate to lead off the inning. Guillen left Contreras on the mound for the Sox, which would later come back to haunt Ozzie. A-Rod led off the inn

You never know what&#39;s going to happen

In the absence of the center of the Marcel Goc and striker Kris Letang, two injured Friday continued. Andrew Ebbett was called on the squad to take the place of GDC, and Bortuzzo walked in letang.notes: Penguins in Rowley won four games in a row, the

【思路、优化】UVa 11491 - Erasing and Winning

Juliano is a fan of the TV show Erasing and Winning, where participants are selected in a draw and receive money for taking part in the show. In the show, the presenter writes a number of N digits in a board. The participant must then erase exactly D

UVA 11491 Erasing and Winning

#include<bits/stdc++.h> #define REP(i,a,b) for(int i=a;i<=b;i++) #define MS0(a) memset(a,0,sizeof(a)) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 using namespace std; typedef long long ll; const int maxn=1000100; const int INF=1

uva 11491:Erasing and Winning(贪心)

题意:给一个长n(n<10^5)位的数,删除d位,求删除后最大的数.(原数无前导0) 思路:从前往后扫,如果a[i] > a[i-1],则删除a[i-1].我暴力的用链表实现了…… #include <cstdio> #include <cstring> #include <cstdlib> #include <list> using namespace std; #define N 100020 char str[N]; int main()