首页 > 其他分享 >【UER #6】逃跑

【UER #6】逃跑

时间:2022-09-03 21:44:41浏览次数:51  
标签:int res void read inline 逃跑 UER mod

题目传送门

Solution

首先我们可以看出求方差的期望其实就是求 \(E(x^2)-E(x)^2\)。

首先考虑怎么求 \(E(x)\)。我们可以发现其实可以对于每一个数去算包含它的路径数,所以我们可以设 \(g(t,x,y)\) 表示 \(t\) 时刻到 \((x,y)\) 的方案数,然后我们可以设 \(f(i)\) 表示时刻 \(i\) 第一次走到的 \((x,y)\) 的方案数之和,于是我们可以得到转移式:

\[f(i)=(w_1+w_2+w_3+w_4)^i-\sum_{j=0}^{i-1} f(j)\times g(i-j,0,0) \]

考虑如何求 \(E(x^2)\)。可以发现的是,\(E(x^2)=2E(\binom{x}{2})+E(x)\),而 \(E(\binom{x}{2})\) 存在组合意义,表示在路径中选两个数出来的方案数。

所以我们可以考虑设 \(h(t,x,y)\) 表示之前到了 \((a,b)\) 然后 \(t\) 时刻到了 \((a+x,b+y)\) 的方案数之和,存在转移式:

\[h(t,x,y)=\sum_{i=0}^{t-1} f(i)\times g(t-i,x,y)-h(i,-x,-y)\times g(t-i,x,y)-h(i,x,y)\times g(t-i,0,0) \]

减的第一个表示先出现 \((a+x,b+y)\) 再到 \((a,b)\) 再到 \((a+x,b+y)\) 的方案数,后面那个数就是去掉 \((a+x,b+y)\) 不是第一个出现的方案数。

然后这个题就可以 \(\Theta(n^4)\) 解决了,似乎用分治 NTT 可以做到 \(\Theta(n^3\log n)\) ?。

Code

#include <bits/stdc++.h>
using namespace std;

#define Int register int
#define mod 998244353
#define MAXN 105

template <typename T> inline void read (T &t){t = 0;char c = getchar();int f = 1;while (c < '0' || c > '9'){if (c == '-') f = -f;c = getchar();}while (c >= '0' && c <= '9'){t = (t << 3) + (t << 1) + c - '0';c = getchar();} t *= f;}
template <typename T,typename ... Args> inline void read (T &t,Args&... args){read (t);read (args...);}
template <typename T> inline void write (T x){if (x < 0){x = -x;putchar ('-');}if (x > 9) write (x / 10);putchar (x % 10 + '0');}
template <typename T> inline void chkmax (T &a,T b){a = max (a,b);}
template <typename T> inline void chkmin (T &a,T b){a = min (a,b);}

int n,w1,w2,w3,w4,g[MAXN][MAXN << 1][MAXN << 1],f[MAXN],pw[MAXN],h[MAXN][MAXN << 1][MAXN << 1];

/*
g[t][i][j]表示时间t到了(i,j)的方案数,f[t]表示时间t第一次到(i,j)的方案之和
h[t][x][y]表示先到(a,b)再到(a+x,b+y)的(a,b)方案数之和(i时刻在(a+x,b+y)) 
*/

int mul (int a,int b){return 1ll * a * b % mod;}
int dec (int a,int b){return a >= b ? a - b : a + mod - b;}
int add (int a,int b){return a + b >= mod ? a + b - mod : a + b;}
int qkpow (int a,int b){
	int res = 1;for (;b;b >>= 1,a = mul (a,a)) if (b & 1) res = mul (res,a);
	return res;
}
void Add (int &a,int b){a = add (a,b);}
void Sub (int &a,int b){a = dec (a,b);}

signed main(){
	read (n,w1,w2,w3,w4);int sum = (w1 + w2 + w3 + w4) % mod;
	g[0][n][n] = pw[0] = 1;for (Int i = 1;i <= n;++ i) pw[i] = mul (pw[i - 1],sum);
	for (Int t = 1;t <= n;++ t)
		for (Int x = -(t - 1);x <= (t - 1);++ x)
			for (Int y = -(t - 1);y <= (t - 1);++ y){
				int tmp = g[t - 1][x + n][y + n];
				Add (g[t][x + 1 + n][y + n],mul (tmp,w1));
				Add (g[t][x - 1 + n][y + n],mul (tmp,w2));
				Add (g[t][x + n][y + 1 + n],mul (tmp,w3));
				Add (g[t][x + n][y - 1 + n],mul (tmp,w4));
			}
	int d1 = 0,d2 = 0;
	for (Int i = 0;i <= n;++ i){
		f[i] = pw[i];
		for (Int j = 0;j <= i - 1;++ j) Sub (f[i],mul (f[j],g[i - j][n][n]));
		Add (d1,mul (f[i],pw[n - i]));
	}
	for (Int t = 1;t <= n;++ t)
		for (Int x = -t;x <= t;++ x)
			for (Int y = -t;y <= t;++ y){
				if (x == 0 && y == 0) continue;
				for (Int i = 0;i <= t - 1;++ i)
					Add (h[t][x + n][y + n],mul (f[i],g[t - i][x + n][y + n])),
					Sub (h[t][x + n][y + n],mul (h[i][-x + n][-y + n],g[t - i][x + n][y + n])),
					Sub (h[t][x + n][y + n],mul (h[i][x + n][y + n],g[t - i][n][n]));
				Add (d2,mul (h[t][x + n][y + n],pw[n - t]));
			}
	d2 = add (d1,add (d2,d2)),write (dec (mul (d2,pw[n]),mul (d1,d1))),putchar ('\n');
	return 0;
}

标签:int,res,void,read,inline,逃跑,UER,mod
From: https://www.cnblogs.com/Dark-Romance/p/16653750.html

相关文章

  • Python爬虫-Pyquery的用法(四)
    一、PyQuery介绍与安装1、PyQuery简介PyQuery简介PyQuery库也是一个非常强大又灵活的网页解析库,如果你有前端开发经验的,都应该接触过jQuery,那么PyQuery就是你非常绝......
  • JQuery——动态添加元素导致点击事件失效
    前言因为博皮当前版本有人反馈文章中标题导航点击无法生成;jquery-click-invalid:https://codesandbox.io/s/jquery-click-invalid-forked-xpt352内容一开始我以为......
  • Python3项目初始化10-->前端基础jquery、ajax,sweetalert--创建用户删除用户改造
    32、JS基础-dmodal点击“创建”,不调整新页面操作,直接弹出框操作。modals弹框指示页面:https://v3.bootcss.com/javascript/#modals拷贝代码,父节点在body里面。<aclass=......
  • jquery与其它插件冲突时
    一般是不会把zepto和jquery一起来用的。但有时候要引入一些插件,可能就会遇到这样的问题。jquerynoConflict()jquery有一个方法叫noConflict(),可以把jquery的$改掉。v......
  • Flask 学习-31.flask_jwt_extended 验证token四种方headers/cookies/json/query_stri
    前言用户携带授权token访问时,其jwt的所处位置列表,默认是在请求头部headers中验证。可以通过JWT_TOKEN_LOCATION进行全局配置,设置token是在请求头部,还是cookies,还是json,......
  • CF1114F Please, another Queries on Array?
    CF1114FPlease,anotherQueriesonArray?题目大意你有一个数组\(a_1,a_2,\dots,a_n\)。现在你需要完成\(q\)次操作,有以下两种操作形式:MULTIPLYlrx,对于所有\(i(......
  • 在 node 中使用 jquery ajax
    对于前端同学来说,ajax请求应该不会陌生。jquery真的ajax请求做了封装,可以通过下面的方式发送一个请求并获取相应结果:$.ajax({url:"https://echo.apipost.cn/get.......
  • jQuery - AJAX get() 和 post() 方法
    jQuery- AJAXget()和post()方法HTTP请求:GETvs.POST两种在客户端和服务器端进行请求-响应的常用方法是:GET和POST。GET -从指定的资源请求数据POST -向......
  • SP1557 GSS2 - Can you answer these queries II
    SP1557GSS2-CanyouanswerthesequeriesII题目大意给出\(n\)个数,\(q\)次询问,求最大子段和,相同的数只算一次。分析看到一个区间内相同的数只能算一次,经验告诉......
  • jquery
    jquery概述:jquery是一个前端的js库,它兼容性好(处理了兼容),它的语法简洁。它是链式调用的语言。以面向对象封装的以返回一个jquery对象为核心来实现对应的链式调用。它集成......