A - Sticker Album Gym - 102861A

29 篇文章 0 订阅

题目链接
题意:每张专辑需要一定的贴纸,购买的专辑上已有的贴纸数不确定。所以需要购买,购买的包中最少有a张贴纸,最多有b张贴纸,问为了填满专辑,每个人需要贴纸数的期望值。
题解:概率dp,开始的时候以为初始的时候每个人都是0张贴纸,然后购买的包的平均值是(a+b)/2,所以很简单,直接用n*2/(a+b),后发现答案不对,重新看题后发现,每个人所拥有的初始值不确定为 0 ~ n中的任意值,所以需要用dp
因为每个人所需要的初始值不确定。所以我们设dp[i]表示当前有i张,仍然需要dp[i]个卡包,最终的答案就是dp[0]。

我们可以发现,每次都可以以1/(b-a+1)得概率拿到(a,a+1~b)个贴纸。
这样很容易推出 :
dp[i]={(dp[i+a]+1)+(dp[i+a+1]+1)+…+(dp[i+b]+1)}/(b-a+1)={dp[i+a]+dp[i+a+1]+…+dp[i+b]}/(b-a+1) + 1;
只需要维护dp[i+a]+dp[i+a+1]+…+dp[i+b]的和即可。

但是还要注意的是,因为当a=0时,后面的推导式中也会出现dp[i],所以应该提出来。
最终的推导式为:
dp[i]={dp[i+1]+dp[i+2]+…+dp[i+b]}/(b-a)+(b-a+1)/(b-a);
下面是AC代码:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
const int N=2e6+10;
double dp[N];
int main()
{
    int a,b;
    int n;
    cin>>n>>a>>b;
    dp[n]=0.0;
    if(a==0)
    {
        double sum=0;
        for(int i=n-1; i>=0; i--)
        {
            dp[i]=sum*1.0/(b-a)+(b-a+1)*1.0/(b-a)*1.0;
            sum+=dp[i];
            sum-=dp[i+b];
        }
    }
    else
    {
        double sum=0;
        for(int i=n-1; i>=0; i--)
        {
            dp[i]=sum*1.0/(b-a+1)+1;
            sum+=dp[i+a-1];
            sum-=dp[i+b];
        }
    }
    printf("%.5lf",dp[0]);
    return 0;

}

为什么倒推:我感觉倒推的原因一方面是边界问题,倒推不用考虑边界,另一方面是根据题设,本来就是倒推的,dp[n]是需要0个,dp[0]是需要n个。这道题问的就是需要多少个卡包,我们就设dp[i]需要几个卡包,这样设之后倒推也就是自然而然地。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sure, here's a potential album concept: Title: WeChat Chronicles 1. Intro: WeChat's Arrival - A short instrumental track that sets the tone for the album, with sounds that evoke the feeling of opening the WeChat app for the first time. 2. Friends List - A catchy pop song that celebrates the joy of adding new friends on WeChat and expanding one's social circle. The lyrics could reference some of WeChat's features, like Shake or People Nearby. 3. Moments - A reflective ballad that explores the emotional ups and downs of sharing one's life on WeChat Moments. The chorus could repeat the phrase "scrolling through my moments" to emphasize the addictive nature of the feature. 4. Group Chats - A lively hip-hop track that celebrates the chaos and camaraderie of WeChat group chats. The verses could feature different rappers representing different types of group chats (e.g. work, school, family) and the different personalities they attract. 5. Mini Programs - A futuristic EDM track that highlights the convenience and innovation of WeChat's mini programs. The lyrics could describe different scenarios where a mini program comes in handy, like ordering food or buying movie tickets. 6. Video Calls - A tender acoustic ballad that captures the intimacy and vulnerability of WeChat video calls. The chorus could include the line "seeing you through my screen" to capture the bittersweet feeling of being far away from loved ones. 7. Wallet - A brassy jazz number that celebrates the financial power of WeChat Wallet. The lyrics could reference different ways people use the feature, like sending red envelopes or paying for groceries. 8. Stickers - A playful pop-punk track that celebrates the art and humor of WeChat stickers. The verses could describe different situations where a specific sticker is the perfect response, and the chorus could encourage listeners to "find your perfect sticker match." 9. Logout - A somber piano ballad that acknowledges the occasional need to disconnect from WeChat and take a break from the hustle and bustle of digital life. The lyrics could encourage listeners to "log out and breathe" and reflect on what truly matters in life. 10. Outro: WeChat's Legacy - A triumphant instrumental track that celebrates the impact and legacy of WeChat on modern communication and socialization. The track could end with a sample of WeChat's signature "ding" notification sound, giving listeners a sense of closure and a reminder of the app's enduring presence.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值