当前位置:网站首页>【NOI模拟赛】刮痧(动态规划)
【NOI模拟赛】刮痧(动态规划)
2022-07-02 11:25:00 【DD(XYX)】
题面
数据范围
对于 100% 的数据, 1 ≤ n ≤ 15 , 1 ≤ m ≤ 100 , 1 ≤ a i ≤ 100 , ∑ a i ≥ m 1\leq n\leq 15,1\leq m\leq 100,1\leq a_i\leq 100,\sum a_i\geq m 1≤n≤15,1≤m≤100,1≤ai≤100,∑ai≥m,不用担心精度问题。
题解
和「通用测评号」是一样的套路。
对操作序列进行考虑,假设一共有 k k k 个怪物被击败,死亡时间从小到大排序是 t 1 , t 2 , . . . , t k t_1,t_2,...,t_k t1,t2,...,tk ,那么在 ( t i , t i + 1 ] (t_i,t_{i+1}] (ti,ti+1] 之间的序列元素,概率权值都是 1 n − i \frac{1}{n-i} n−i1 。一种概率权值序列的贡献,等于概率权值乘积乘上对应该权值序列的操作序列方案数。
具体地,我们可以把被击败的怪物和不会被击败的怪物分开考虑,当我们确定被击败的怪物集合 S S S 以及被击败的怪物在操作序列中的排布,即同时确定了概率权值序列时,剩下的就是不会被击败的怪物在固定的位置上随便放的方案数了。
令 g [ i ] [ S ] g[i][S] g[i][S] 表示不会被击败的怪物集合为 S S S ,总损失血量为 i i i 的方案数,这个可以背包转移,处理时间复杂度 O ( 2 n m 2 ) O(2^nm^2) O(2nm2) ,常数 <1。
接下来确定概率权值序列,令 f [ i ] [ S ] f[i][S] f[i][S] 表示当前已经刮了 i i i ,已被击败怪物集合为 S S S ,所有方案的权值积总和。我们往后填操作序列,挨个确定 t i t_i ti 以及被击败的怪物 j j j,确定时再往操作序列里放 a j a_j aj 个 j j j 。令 s u m [ S ] = ∑ i ∈ S a i sum[S]=\sum_{i\in S} a_i sum[S]=∑i∈Sai,转移如下:
- 当前位置不属于 { t } \{t\} { t} : f [ i + 1 ] [ S ] ← f [ i ] [ S ] ⋅ 1 n − ∣ S ∣ f[i+1][S]\leftarrow f[i][S]\cdot\frac{1}{n-|S|} f[i+1][S]←f[i][S]⋅n−∣S∣1
- 当前位置属于 { t } \{t\} { t} : f [ i + 1 ] [ S ∪ j ] ← f [ i ] [ S ] ⋅ ( i − s u m [ S ] a j − 1 ) ⋅ 1 n − ∣ S ∣ f[i+1][S\cup{j}]\leftarrow f[i][S]\cdot{i-sum[S]\choose a_j-1}\cdot\frac{1}{n-|S|} f[i+1][S∪j]←f[i][S]⋅(aj−1i−sum[S])⋅n−∣S∣1
时间复杂度 O ( 2 n n m ) O(2^nnm) O(2nnm) 。
答案为 ∑ S f [ m ] [ S ] ⋅ g [ m − s u m [ S ] ] [ S ‾ ] ⋅ ∣ S ∣ \sum_{S}f[m][S]\cdot g[m-sum[S]][\overline S]\cdot |S| ∑Sf[m][S]⋅g[m−sum[S]][S]⋅∣S∣
CODE
#include<map>
#include<set>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<random>
#include<bitset>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
#define MAXN 105
#define LL long long
#define ULL unsigned long long
#define ENDL putchar('\n')
#define DB double
#define lowbit(x) (-(x) & (x))
#define FI first
#define SE second
#define PR pair<int,int>
#define UIN unsigned int
int xchar() {
static const int maxn = 1000000;
static char b[maxn];
static int pos = 0,len = 0;
if(pos == len) pos = 0,len = fread(b,1,maxn,stdin);
if(pos == len) return -1;
return b[pos ++];
}
// #define getchar() xchar()
inline LL read() {
LL f = 1,x = 0;int s = getchar();
while(s < '0' || s > '9') {
if(s<0)return -1;if(s=='-')f=-f;s = getchar();}
while(s >= '0' && s <= '9') {
x = (x<<1) + (x<<3) + (s^48);s = getchar();}
return f*x;
}
void putpos(LL x) {
if(!x)return ;putpos(x/10);putchar((x%10)^48);}
inline void putnum(LL x) {
if(!x) {
putchar('0');return ;}
if(x<0) putchar('-'),x = -x;
return putpos(x);
}
inline void AIput(LL x,int c) {
putnum(x);putchar(c);}
int n,m,s,o,k;
int a[MAXN],id[1<<15|5],sm[1<<15|5],ct[1<<15|5];
DB g[MAXN][1<<15|5];
DB f[MAXN][1<<15|5];
DB C[MAXN][MAXN];
int main() {
freopen("scraping.in","r",stdin);
freopen("scraping.out","w",stdout);
n = read(); m = read();
for(int i = 1;i <= n;i ++) {
a[i] = read();
}
C[0][0] = 1;
for(int i = 1;i <= m;i ++) {
C[i][0] = C[i][i] = 1;
for(int j = 1;j < i;j ++) {
C[i][j] = C[i-1][j-1] + C[i-1][j];
}
}
int tp = (1<<n)-1;
for(int i = 1;i <= n;i ++) id[1<<(i-1)] = i;
for(int i = 1;i <= tp;i ++) {
sm[i] = sm[i^lowbit(i)] + a[id[lowbit(i)]];
ct[i] = ct[i^lowbit(i)] + 1;
}
for(int i = 0;i <= tp;i ++) g[0][i] = 1;
for(int i = 1;i <= m;i ++) {
for(int j = 1;j <= tp;j ++) {
g[i][j] = g[i][j^lowbit(j)];
int d = id[lowbit(j)],jj = j^lowbit(j);
for(int k = 1;k <= i && k < a[d];k ++) {
g[i][j] += g[i-k][jj] * C[i][k];
}
}
}
f[0][0] = 1;
for(int i = 0;i < m;i ++) {
for(int j = 0;j < tp;j ++) {
if(sm[j] > i) continue;
f[i+1][j] += f[i][j]/ct[j^tp];
for(int k = 1;k <= n;k ++) {
if(!(j & (1<<(k-1)))) {
if(sm[j]+a[k] <= i+1) f[i+1][j|(1<<(k-1))] += f[i][j]*C[i-sm[j]][a[k]-1]/ct[j^tp];
}
}
}
}
DB as = 0;
for(int i = 1;i <= tp;i ++) {
if(sm[i] <= m) as += f[m][i] * g[m-sm[i]][i^tp] * ct[i];
}
as = floor(as*100000.0 + 0.5) * 1e-5;
printf("%.5f\n",as);
return 0;
}
边栏推荐
- 2. Const pointer
- Onnx+tensorrt: write preprocessing operations to onnx and complete TRT deployment
- [QNX Hypervisor 2.2用户手册]6.3 Guest与外部之间通信
- tmall. product. schema. Get (product information acquisition schema acquisition), Taobao store upload commodity API interface, Taobao commodity publishing interface, Taobao commodity upload API interf
- 4. Array pointer and pointer array
- 测试框架TestNG的使用(二):testNG xml的使用
- 1、编辑利器vim
- < schematic diagram of oral arithmetic exercise machine program development> oral arithmetic exercise machine / oral arithmetic treasure / children's math treasure / children's calculator LCD LCD driv
- Method of creating linked server for cross server data access
- threejs的控制器 立方體空間 基本控制器+慣性控制+飛行控制
猜你喜欢
mathML转latex
Design and implementation of car query system based on php+mysql
QT new project
[Space & single cellomics] phase 1: single cell binding space transcriptome research PDAC tumor microenvironment
Method of creating linked server for cross server data access
提示:SQL Server 阻止了对组件‘Ad Hoc Distributed Queries ‘的STATEMENT ‘OpenRowset/OpenDatasource“”
Implement a server with multi process concurrency
Available solution development oral arithmetic training machine / math treasure / children's oral arithmetic treasure / intelligent math treasure LCD LCD driver ic-vk1622 (lqfp64 package), original te
Add vector formula in rich text editor (MathType for TinyMCE, visual addition)
Fatal: unsafe repository is owned by someone else
随机推荐
PyQt5_ Qscrollarea content is saved as a picture
2. Const pointer
MQ教程 | Exchange(交换机)
Yolov6 training: various problems encountered in training your dataset
Understanding of mongodb
PTA question bank== > complex four operations, one for one, examination seat number (7-73)
Fabric.js 橡皮擦的用法(包含恢复功能)
taobao. trade. memo. Add (add remarks to a transaction) interface, Taobao store flag insertion interface, Taobao order flag insertion API interface, oauth2.0 interface
YoloV6训练:训练自己数据集遇到的各种问题
Certik released the defi security report in 2021, disclosing key data of industry development (PDF download link attached)
4、数组指针和指针数组
OpenCV调用USB摄像头的点滴
4. Array pointer and pointer array
检查密码
mongodb的认识
由粒子加速器产生的反中子形成的白洞
Solving the longest subsequence with linear DP -- three questions
How many knowledge points can a callable interface have?
Tmall product details interface (APP, H5 end)
《可供方案开发》口算训练机/数学宝/儿童口算宝/智能数学宝 LCD液晶显示驱动IC-VK1622(LQFP64封装),原厂技术支持