#期望dp#洛谷 1365 bzoj 3450 Easy

news/2025/1/19 15:41:25/

题目

n n n次点击要做,成功了就是 o o o,失败了就是 x x x,分数是按 c o m b o combo combo计算的,连续 a a a c o m b o combo combo就有 a × a a\times a a×a分, c o m b o combo combo就是极大的连续 o o o。有些地方 o o o或者 x x x各有 1 2 \frac{1}{2} 21的可能性,用 ? ? ?号来表示。期望得分是多少


分析

那么首先设 f [ n ] f[n] f[n]表示到 n n n的总期望 c o m b o combo combo, g [ n ] g[n] g[n]表示到 n n n的连续一段 o o o的总长度,
那么就可以得到

  • s [ n ] = x , f [ n ] = f [ n − 1 ] , g [ n ] = 0 s[n]=x,f[n]=f[n-1],g[n]=0 s[n]=x,f[n]=f[n1],g[n]=0
  • s [ n ] = o , f [ n ] = f [ n − 1 ] + 2 × g [ n − 1 ] + 1 , g [ n ] = g [ n − 1 ] + 1 ( 也 就 是 说 , 用 之 前 的 c o m b o , 按 完 全 平 方 公 式 拆 开 , 加 上 的 就 是 2 倍 长 度 + 1 , 同 时 期 望 长 度 也 要 增 加 一 ) s[n]=o,f[n]=f[n-1]+2\times g[n-1]+1,g[n]=g[n-1]+1(也就是说,用之前的combo,按完全平方公式拆开,加上的就是2倍长度+1,同时期望长度也要增加一) s[n]=o,f[n]=f[n1]+2×g[n1]+1,g[n]=g[n1]+1(combo2+1)
  • s [ n ] = ? , 其 实 和 o 很 类 似 , 但 是 f [ n ] = f [ n − 1 ] + g [ n − 1 ] + 0.5 ( 后 面 两 项 有 一 半 的 概 率 ) , g [ n ] = ( g [ n − 1 ] + 1 ) ÷ 2 s[n]=?,其实和o很类似,但是f[n]=f[n-1]+g[n-1]+0.5(后面两项有一半的概率),g[n]=(g[n-1]+1)\div 2 s[n]=?,of[n]=f[n1]+g[n1]+0.5()g[n]=(g[n1]+1)÷2

代码

#include <cstdio>
#define rr register
using namespace std;
int n,p; double f[2],g[2];
signed main(){for (scanf("%d",&n);n;--n){rr char c=getchar(); p^=1;while (c!='o'&&c!='x'&&c!='?') c=getchar();if (c=='x') f[p]=f[p^1],g[p]=0;else if (c=='o') f[p]=f[p^1]+2*g[p^1]+1,g[p]=g[p^1]+1;else f[p]=f[p^1]+g[p^1]+0.5,g[p]=(g[p^1]+1)*0.5;}return !printf("%.4lf",f[p]);
}

http://www.ppmy.cn/news/201299.html

相关文章

ExpressBox 3450

Magma的ExpressBox 3450提供最佳的GPU和其他HPC的外围扩展现有的主机系统。为了支持全创3 x16 PCIe连接的所有设备&#xff0c;这是一个完美的伴侣eb3450工作站和服务器。高达四的双宽&#xff08;如GPU&#xff09;和一个宽的PCIe设备都支持通过扩展。 郭小姐 18874824200 0…

bzoj3450 (概率dp)

题意:有一个长度为 n 的字符串&#xff0c;由 o,x,? 三种字符组成。? 代表 o,x 各有 50% 概率。求连续 o长度的平方和的期望。 思路:由平方公式可得,那么就可以设i之前连续的o的长度期望为f[i]. 如果s[i]o那么答案贡献为f[i-1]*21,f[i]f[i-1]1. 如果s[i]xf[i]0,贡献也为0 …

POJ - 3450

题目链接&#xff1a;http://poj.org/problem?id3450 Corporate Identity Time Limit: 3000MS Memory Limit: 65536KTotal Submissions: 8549 Accepted: 2856 Description Beside other services, ACM helps companies to clearly state their “corporate identity”, which …

BZOJ 3450 Easy

Description 某一天WJMZBMR在打osu~~~但是他太弱逼了&#xff0c;有些地方完全靠运气:( 我们来简化一下这个游戏的规则 有n次点击要做&#xff0c;成功了就是o&#xff0c;失败了就是x&#xff0c;分数是按comb计算的&#xff0c;连续a个comb就有a*a分&#xff0c;comb就是极大…

hdu3450

开始看觉得是dp&#xff0c;复杂度O(n^2)会超时就没做&#xff0c;应该是用线段树或者树状数组&#xff0c;加上离散化和二分法优化。 你需要一个dp[i]数组&#xff0c;存储的是以i为结尾的个数&#xff0c;结果就是dp[]之和. 离散化的部分是用一个离散化结构体&#xff0c;最…

3450

/* KMP来做532ms */// include file #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cctype> #include <ctime>#include <iostream> #include <sstream> #include <fstream> #in…

BZOJ3450 Easy

原题链接&#xff1a;http://www.lydsy.com/JudgeOnline/problem.php?id3450 Easy Description 某一天WJMZBMR在打osu~~~但是他太弱逼了&#xff0c;有些地方完全靠运气:( 我们来简化一下这个游戏的规则 有n次点击要做&#xff0c;成功了就是o&#xff0c;失败了就是x&…

tjut 3450

/*分析:每次寻找以a[i]结尾的子序列能有多少个,只需要寻找a[i]-d和a[i]d之之间数结尾的子序列 的全部个数,然后把a[i]直接放在那些数后面即可 找寻和更新都是用树状数组 */ #include <iostream> #include <cstdio> #include <cstdlib> #include …