ZOJ3640(期望dp)

7 篇文章 0 订阅

题解:

期望dp重要是转移状态的确定,而一般来说转移状态一般会用一个有范围的状态去限定,这题有限的状态量可以想到的是Cain的攻击力,(不超过2e4)
于是可以确定以下状态 d p [ i ] dp[i] dp[i]表示在当前攻击为i时所需要的天数期望
于是可以自然想到转移

  1. 如果i值大于c[i]则 d p [ i ] + = t [ i ] / n dp[i]+=t[i]/n dp[i]+=t[i]/n
  2. 否则 d p [ i ] + = ( d p [ i + c [ i ] ] + 1 ) / n dp[i]+=(dp[i+c[i]]+1)/n dp[i]+=(dp[i+c[i]]+1)/n

(代码中的排序是不必要的,一开始想了一个假算法=。=)

代码:

#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;}
const db EPS=1e-9;
inline int sign(db a){return a<-EPS?-1:a>EPS;}
inline int cmp(db a,db b){return sign(a-b);}
ll c[N],t[N];
db dp[N];
int n,f;
db dfs(int x){
    if(cmp(dp[x],0)>=0) return dp[x];
    db res=0;
    for(int i=1;i<=n;i++){
        if(x>c[i]) res+=1.0*t[i]/n;
        else res+=1.0*(dfs(x+c[i])+1)/n;
    }
    return dp[x]=res;
}
int main(){
    //freopen("1.txt","r",stdin);
    //ios::sync_with_stdio(false);
    while(~scanf("%d%d",&n,&f)){
        for(int i=1;i<=n;i++){
            scanf("%lld",&c[i]);
        }
        sort(c+1,c+1+n);
        for(int i=1;i<=n;i++) t[i]=(ll)(1.0*(1+sqrt(5))*c[i]*c[i]/2.0);
//        for(int i=1;i<=n;i++) cout<<t[i]<<' ';
//        cout<<endl;
        for(int i=0;i<=20000;i++) dp[i]=-1;
        printf("%.3f\n",dfs(f));
    }
    //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、付费专栏及课程。

余额充值