当前位置:网站首页>[noi Simulation Competition] scraping (dynamic planning)
[noi Simulation Competition] scraping (dynamic planning)
2022-07-02 14:59:00 【DD(XYX)】
Topic

Data range
about 100% The data of , 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, Don't worry about accuracy .
Answer key
and 「 General evaluation number 」 It's the same routine .
Consider the sequence of operations , Let's say there are k k k Monsters were defeated , The order of death time from small to large is t 1 , t 2 , . . . , t k t_1,t_2,...,t_k t1,t2,...,tk , So in ( t i , t i + 1 ] (t_i,t_{i+1}] (ti,ti+1] Sequence elements between , Probability weights are 1 n − i \frac{1}{n-i} n−i1 . The contribution of a sequence of probability weights , Equal to the product of probability weight multiplied by the number of operation sequence schemes corresponding to the weight sequence .
In particular , We can consider defeated monsters and monsters that will not be defeated separately , When we determine the set of defeated monsters S S S And the arrangement of defeated monsters in the operation sequence , That is, when the probability weight sequence is determined at the same time , What's left is the number of schemes that will not be defeated monsters put casually in a fixed position .
Make g [ i ] [ S ] g[i][S] g[i][S] Indicates that the monsters that will not be defeated are S S S , The total blood loss is i i i Number of alternatives , This can be transferred by backpack , Processing time complexity O ( 2 n m 2 ) O(2^nm^2) O(2nm2) , constant <1.
Next, determine the probability weight sequence , Make f [ i ] [ S ] f[i][S] f[i][S] Indicates that it has been scraped i i i , The defeated monsters are gathered as S S S , Sum of weight products of all schemes . Let's fill in the operation sequence later , Confirm one by one t i t_i ti And defeated monsters j j j, Put... Into the operation sequence when it is confirmed a j a_j aj individual j j j . Make s u m [ S ] = ∑ i ∈ S a i sum[S]=\sum_{i\in S} a_i sum[S]=∑i∈Sai, Transfer as follows :
- The current location does not belong to { 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
- The current location belongs to { 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
Time complexity O ( 2 n n m ) O(2^nnm) O(2nnm) .
The answer for ∑ 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;
}
边栏推荐
- 电脑怎么设置扬声器播放麦克风的声音
- 实用调试技巧
- LeetCode_字符串_简单_412.Fizz Buzz
- geoserver离线地图服务搭建和图层发布
- Error: NPM warn config global ` --global`, `--local` are deprecated Use `--location=global` instead.
- 可视化搭建页面工具的前世今生
- 使用mathtype编辑公式,复制粘贴时设置成仅包含mathjax语法的公式
- Xilinx Vivado set *.svh as SystemVerilog Header
- info [email protected] : The platform “win32“ is incompatible with this module.
- STM32 library function for GPIO initialization
猜你喜欢

【空间&单细胞组学】第1期:单细胞结合空间转录组研究PDAC肿瘤微环境

JMeter script parameterization

A white hole formed by antineutrons produced by particle accelerators

【C语言】详解指针的初阶和进阶以及注意点(1)

Btrace- (bytecode) dynamic tracking tool

GeoServer offline map service construction and layer Publishing

【C语音】详解指针进阶和注意点(2)

【无标题】LeetCode 2321. 拼接数组的最大分数

About text selection in web pages and counting the length of selected text

一张图彻底掌握prototype、__proto__、constructor之前的关系(JS原型、原型链)
随机推荐
geoserver离线地图服务搭建和图层发布
C语言实现N皇后问题
Threejs controller cube space basic controller + inertia control + flight control
STM32库函数进行GPIO初始化
Thoroughly master prototype__ proto__、 Relationship before constructor (JS prototype, prototype chain)
解决el-radio-group 回显后不能编辑问题
MFC CString to char*
4. Array pointer and pointer array
C# richTextBox控制显示最大行数
btrace-(字节码)动态跟踪工具
Reuse and distribution
Fatal: unsafe repository is owned by someone else
tmall. product. schema. Get (product information acquisition schema acquisition), Taobao store upload commodity API interface, Taobao commodity publishing interface, Taobao commodity upload API interf
3. Function pointers and pointer functions
Large top heap, small top heap and heap sequencing
taobao. trade. Get (get some information of a single transaction), Taobao store order interface, Taobao oauth2.0 interface, Taobao R2 interface code docking and sharing
STM32标准固件库函数名(一)
obsidian安装第三方插件——无法加载插件
Advanced C language (learn malloc & calloc & realloc & free in simple dynamic memory management)
mathjax 入门(web显示数学公式,矢量的)