手动博客搬家: 本文发表于20181212 09:37:21, 原地址https://blog.csdn.net/suncongbo/article/details/84962727 呜啊怎么又是数学了啊...数学比例\(\frac{16}{33}=0.4848\) orz yhx-12243神仙 题目链接: https://codeforces.com/contest/947/problem/E 题意: 有一个\([0,n]\)的随机数\(x\)初始为\(i\)的概率为\(p_i\). \(m…
题意:你要在纸上画一个长度为n * m的括号序列,第i个位置画左括号的花费是a[i % n], 画右括号的花费是b[i % n],问画完这个括号序列的最小花费.n <= 20, m <= 1e7 思路:如果不管n和m的限制,这个题很好做,设dp[i][j]是到i位置,平衡因子是j的花费,dp[i][j] = min(dp[i - 1][j - 1] + a[i], dp[i - 1][j + 1] + b[i]),但是这样n * m到2e8级别,这是我们无法承受的.不过,我们可以发现一个性质:…
Codeforces 题目传送门 & 洛谷题目传送门 神仙题 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 首先考虑最朴素的 \(dp\),设 \(dp_{z,i}\) 表示经过 \(z\) 次操作后剩下的数为 \(i\) 的概率,那么显然有 \(dp\) 转移方程 \(dp_{z,i}=\sum\limits_{j\ge i}dp_{z-1,j}·\dfrac{1}{j+1}\). 边界条件 \(dp_{0,i}=p_i\) 直接递推显然不行,考虑优化,我们记 \(F_z(x)…
[CF932E]Perpetual Subtraction(NTT,线性代数) 题面 洛谷 CF 题解 设\(f_{i,j}\)表示\(i\)轮之后这个数恰好为\(j\)的概率. 得到转移:\(\displaystyle f_{i,j}=\sum_{k=j}^{n}f_{i-1,k}*\frac{1}{k+1}\). 看成生成函数就有\(\displaystyle F_i(x)=\sum_{j=0}^{n}x^j\sum_{k\ge j}\frac{f_{i-1,k}}{k+1}\). 把两维换…
题目链接:http://codeforces.com/contest/219/problem/D 树dp //#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include…
链接:https://www.luogu.org/problemnew/show/P1939 题解: 矩阵优化dp模板题 搞清楚矩阵是怎么乘的构造一下矩阵就很简单了 代码: #include <bits/stdc++.h> using namespace std; #define ll long long #define mo 1000000007 ll t,x; struct re{ ll jz[][]; }a,c; re XX(re x,re y) { re tmp; memset(tmp…
我的第一道需要程序建矩阵的矩阵优化DP. 题目可以将不同的p分开处理. 对于p==0 || p==1 直接是0或1 对于p>1,就要DP了.这里以p==3为例: 设dp[i][s1][s2][r]为前i列,结尾为0的有s1行(0表示女生,1表示男生),结尾为01的有s2个,结尾为011的有n-s1-s2个,有r列全是1的方案数. 状态这么复杂,看起来一点也不能用矩阵优化,但我们可以将状态(s1,s2,r)hash成整数,然后建立状态之间的转移. 收获: 这种m超过10^7的一般都要用矩阵优化,如…
On Saint Valentine's Day, Alex imagined to present a special pendant to his girl friend made by K kind of pearls. The pendant is actually a string of pearls, and its length is defined as the number of pearls in it. As is known to all, Alex is very ri…
题目链接 Solution 矩阵优化 \(dp\). 题中给出的式子的意思就是: 求 nk 个物品中选出 mod k 为 r 的个数的物品的方案数. 考虑朴素 \(dp\) ,定义状态 \(f[i][j]\) 代表前 \(i\) 个物品选择 \(mod~k\) 为 \(j\) 的方案数. 那么转移方程也很简单 : \[f[i][j]_{j\in[1,i)}=f[i-1][j]+f[i-1][(j-1+k)mod~k]\] 但是很显然这样是 \(O(n^2k)\) . 考虑优化,发现对于每一项状态…
[CodeForces - 1272D] Remove One Element [线性dp] 标签:题解 codeforces题解 dp 线性dp 题目描述 Time limit 2000 ms Memory limit 262144 kB Source Codeforces Round #605 (Div. 3) Tags brute force   dp   *1500 Site https://codeforces.com/problemset/problem/1272/D 题面 Exam…