题面在这里

题意

不好描述.....大家还是看luogu上的吧(资磁洛谷!)

sol

\(n<=15\)的良心数据肯定是状压啦

只是设状态的时候有点头疼

首先思考我们在无法预知之后宝物的情况下如何求解

对于第i个宝物,如果我们没有满足吃掉的条件的话就只能放弃(可惜...)

如果我们能吃掉,那么就需要观察吃掉它和不吃掉它的期望哪个更高,从更优的期望中进行决策

所以这样的思路让我们必须倒着DP

设\(f[i][x]\)表示当前已经吃掉的宝物状态为x的时候,迎接第i个宝物,在最优决策下所能得到的期望

之后按照上面的思路转移即可

代码

#include<bits/stdc++.h>
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<vector>
#include<cstdio>
#include<string>
#include<bitset>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define mp make_pair
#define pb push_back
#define RG register
#define il inline
using namespace std;
const int mod=1e9+7;
const int N=16;
const double eps=1e-10;
typedef unsigned long long ull;
typedef vector<int>VI;
typedef long long ll;
typedef double dd;
il ll read(){
RG ll data=0,w=1;RG char ch=getchar();
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')w=-1,ch=getchar();
while(ch<='9'&&ch>='0')data=data*10+ch-48,ch=getchar();
return data*w;
} dd f[105][65537];
int k,n,p[N],need[N][N],g[65537];
bool check[65537]; il bool pd(int x){//判断一个状态是否为合法状态
for(RG int i=1;i<=n;i++)
if((x&(1<<(i-1)))==(1<<(i-1)))
for(RG int j=1;j<=need[i][0];j++)
if((x&(1<<(need[i][j]-1)))!=(1<<(need[i][j]-1)))
return 0;
return 1;
} il void DP(){
for(RG int i=k;i;i--)
for(RG int j=1,x=g[j];j<=g[0];j++,x=g[j]){
for(RG int a=1;a<=n;a++){
if(check[x|(1<<(a-1))]&&f[i+1][x|(1<<(a-1))]+p[a]>f[i+1][x]){
//在选择合法的情况下,吃掉更优
f[i][x]+=f[i+1][x|(1<<(a-1))]+p[a];
}
else f[i][x]+=f[i+1][x];//不能吃或不吃更优
}
f[i][x]/=n;
}
} int main()
{
k=read();n=read();
for(RG int i=1,x;i<=n;i++){
p[i]=read();
while(x=read())need[i][++need[i][0]]=x;
} for(RG int i=0;i<(1<<n);i++)
if(check[i]=pd(i))g[++g[0]]=i;
//预处理出所有合法状态 DP(); printf("%.6lf\n",f[1][0]);
return 0;
}

友链

SYCdalao的题解见这里

最新文章

  1. QT toLocal8Bit奇怪的问题
  2. vs2015手动安装xamarin
  3. 正态QQ图的原理
  4. 在Android软按键中添加Menu键
  5. Android 点击文字实现跳转
  6. POJ 1733 Parity game(离散化+带权并查集)
  7. VS2008的默认打开重置为VS2008
  8. C#运用实例.读取csv里面的词条,对每一个词条抓取百度百科相关资料,然后存取到数据库
  9. 2014 HDU多校弟八场H题 【找规律把】
  10. IIS优化服务器性能导致QuartZ任务未运行
  11. 自定义MapReduce中数据类型
  12. WEP无线加密破解
  13. msf入门学习笔记
  14. C# 构造函数总结
  15. 【JDBC】Java 连接 MySQL 基本过程以及封装数据库工具类
  16. returnFunc.js
  17. ansible-task模块写法归类
  18. springboot+rabbitmq整合示例程
  19. ERROR: child process failed, exited with error number 100
  20. 【Selenium-WebDriver自学】Selenium-RC脚本编写(十)

热门文章

  1. [Python Study Notes]实现对鼠标控制
  2. java生产者与消费者模式
  3. Linux 快速执行历史命令,用 !编号
  4. 免费 Https 证书(Let&#39;s Encrypt)申请与配置
  5. ubuntu安装nginx和设置网站https访问
  6. chrome浏览器下JavaScript实现clipboard时无法访问剪切板解决方案
  7. 搭建VUE项目的准备(利用vue-cli来构建项目)
  8. Linux下yum安装MysqL数据库
  9. pc浏览器css和js计算浏览器宽度的差异以及和滚动条的关系
  10. MacOS App代码申请管理员权限