当前位置:网站首页>[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;
}
边栏推荐
- Thoroughly master prototype__ proto__、 Relationship before constructor (JS prototype, prototype chain)
- 【NOI模拟赛】刮痧(动态规划)
- mathjax 入门(web显示数学公式,矢量的)
- [Space & single cellomics] phase 1: single cell binding space transcriptome research PDAC tumor microenvironment
- taobao.trade.memo.add( 对一笔交易添加备注 )接口,淘宝店铺插旗接口,淘宝订单插旗API接口,oAuth2.0接口
- Advanced C language (realize simple address book)
- 实用调试技巧
- 电脑怎么设置扬声器播放麦克风的声音
- geoserver离线地图服务搭建和图层发布
- Xilinx Vivado set *. svh as SystemVerilog Header
猜你喜欢

It's no exaggeration to say that this is the most user-friendly basic tutorial of pytest I've ever seen

Factal: Unsafe repository is owned by someone else Solution

蜻蜓低代码安全工具平台开发之路

Makefile separates file names and suffixes

LeetCode 2320. Count the number of ways to place the house

taobao.trade.memo.add( 对一笔交易添加备注 )接口,淘宝店铺插旗接口,淘宝订单插旗API接口,oAuth2.0接口

报错:npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

Socket and socket address

taobao. trade. memo. Add (add remarks to a transaction) interface, Taobao store flag insertion interface, Taobao order flag insertion API interface, oauth2.0 interface

MFC 定时器使用
随机推荐
1. Editing weapon VIM
forEach的错误用法,你都学废了吗
fatal: unsafe repository is owned by someone else 的解决方法
Find the maximum inscribed circle of the contour
[QNX Hypervisor 2.2用户手册]6.3 Guest与外部之间通信
一张图彻底掌握prototype、__proto__、constructor之前的关系(JS原型、原型链)
C# 线程传参
4、数组指针和指针数组
使用mathtype编辑公式,复制粘贴时设置成仅包含mathjax语法的公式
##51单片机实验之简易验证码发生器
4. Array pointer and pointer array
It's no exaggeration to say that this is the most user-friendly basic tutorial of pytest I've ever seen
C RichTextBox controls the maximum number of lines displayed
IE 浏览器正式退休
LeetCode 209. 长度最小的子数组
info [email protected]: The platform “win32“ is incompatible with this module.
用户隐私协议有些汉字编码不规范导致网页显示乱码,需要统一找出来处理一下
Some Chinese character codes in the user privacy agreement are not standardized, which leads to the display of garbled codes on the web page. It needs to be found and handled uniformly
3. Function pointers and pointer functions
STM32 library function for GPIO initialization