URAL 1776 C - Anniversary Firework 区间DP

点击打开链接

题意:

要把1-n个火箭都点火,其中每次点火间隔10s.

点火步骤:1、首先点燃第一个和最后一个2、点燃任意两个已点火箭的中间一个。注意可以有多个区间,每次可以同时点燃多个。

求点燃所有火箭的时间的期望。

思路:

首先,期望取最大值这个是错误的

这个dp[i][j]应该表示长度为i的,放j个火箭的概率是多少

直接dfs解决就好了  【dalao专用:直接什么什么就好了,很显然巴拉巴拉巴拉....】

并不会,也不是很理解...


代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define mp(x,y) make_pair(x,y)
const int maxn = 400+10;
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//

double dp[maxn][maxn];
int vis[maxn][maxn];

double dfs(int x,int y){
	if(vis[x][y]) return dp[x][y];
	if(x==0) return 1.0;
	if(y==0) return 0.0;
	double p = 1.0/x;
	double ans = 0;
	for(int k=1; k<=x; k++)
		ans += p * dfs(k-1,y-1) * dfs(x-k,y-1);
	vis[x][y] = 1;
	return dp[x][y] = ans;
}

int main(){
	int n = read();
	double ans = 0;
	mem(dp),mem(vis);
	for(int i=1; i<=n-2; i++)
		ans += (dfs(n-2,i)-dfs(n-2,i-1)) * i*10;
	printf("%.10lf\n",ans);

    return 0;
}

//https://vjudge.net/contest/87643#problem/C


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值