题解:
期望dp重要是转移状态的确定,而一般来说转移状态一般会用一个有范围的状态去限定,这题有限的状态量可以想到的是Cain的攻击力,(不超过2e4)
于是可以确定以下状态
d
p
[
i
]
dp[i]
dp[i]表示在当前攻击为i时所需要的天数期望
于是可以自然想到转移
- 如果i值大于c[i]则 d p [ i ] + = t [ i ] / n dp[i]+=t[i]/n dp[i]+=t[i]/n
- 否则 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;
}