当前位置:网站首页>[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;
}
边栏推荐
猜你喜欢
A white hole formed by antineutrons produced by particle accelerators
Obsidian installs third-party plug-ins - unable to load plug-ins
【apipost】使用教程
LeetCode - 搜索二维矩阵
Btrace- (bytecode) dynamic tracking tool
Li Chuang EDA learning notes 15: draw border or import border (DXF file)
Full of knowledge points, how to use JMeter to generate encrypted data and write it to the database? Don't collect it quickly
MQ tutorial | exchange (switch)
Introduction to mathjax (web display of mathematical formulas, vector)
C code audit practice + pre knowledge
随机推荐
【无标题】LeetCode 2321. 拼接数组的最大分数
buuctf-pwn write-ups (7)
Ad20 cannot select the solution of component packaging in PCB editor
MFC A对话框调用B对话框函数并传参
[Space & single cellomics] phase 1: single cell binding space transcriptome research PDAC tumor microenvironment
STM32库函数进行GPIO初始化
Have you learned the wrong usage of foreach
MFC 控制台打印,弹出对话框
LeetCode 2320. Count the number of ways to place the house
用户隐私协议有些汉字编码不规范导致网页显示乱码,需要统一找出来处理一下
【C语音】详解指针进阶和注意点(2)
实现一个多进程并发的服务器
Fatal: unsafe repository is owned by someone else
Why can't browsers read JSX?
检查密码
Introduction to C language -- array
表格响应式布局小技巧
Contrôleur pour threejs cube Space Basic Controller + Inertial Control + Flight Control
Leetcode - Search 2D matrix
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