BZOJ4318:OSU!(概率dp)

7 篇文章 0 订阅

题解:

这种 x 3 x^3 x3的题很容易想到用 x 2 x^2 x2, x 1 x^1 x1这两个状态来转移过来。
因为我们发现 ( x + 1 ) 3 (x+1)^3 (x+1)3拆开可以用这三个东西来表示。
于是定义状态 d p [ i ] [ 3 ] dp[i][3] dp[i][3]
第二维的1表示长链尾部连续1的 x 1 x^1 x1
2表示长链尾部连续1的 x 2 x^2 x2
3表示答案
详细转移见代码 核心思想就是三次方和平方的分解

代码:

#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
//#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define PB push_back
#define MP make_pair
#define INF 1073741824
#define inf 1152921504606846976
#define pi 3.14159265358979323846
//#pragma comment(linker,"/STACK:10240000,10240000")
//mt19937 rand_(time(0));
const int N=3e5+7,M=2e6;
const long long mod=1e9+7;
inline int read(){int ret=0;char ch=getchar();bool f=1;for(;!isdigit(ch);ch=getchar()) f^=!(ch^'-');for(;isdigit(ch);ch=getchar()) ret=(ret<<1)+(ret<<3)+ch-48;return f?ret:-ret;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}//逆元
//int head[N],NEXT[M],ver[M],tot;void link(int u,int v){ver[++tot]=v;NEXT[tot]=head[u];head[u]=tot;}

db dp[N][5];
db p[N];
int main(){
    //freopen("1.txt","r",stdin);
    //ios::sync_with_stdio(false);
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lf",&p[i]);
    }
    for(int i=1;i<=n;i++){
        dp[i][1]=(dp[i-1][1]+1)*p[i];
        dp[i][2]=(dp[i-1][2]+dp[i-1][1]*2.0+1)*p[i];
        dp[i][3]=dp[i-1][3]+(dp[i-1][2]*3.0+dp[i-1][1]*3.0+1)*p[i];
    }
    printf("%.1f\n",(ll)((dp[n][3]*10.0+0.5))/10.0);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值