题意:有一个n * m的棋盘,你初始在点(1, 1),你需要去点(n, m)。你初始有s分,在这个棋盘上有k个点,经过一次这个点分数就会变为s / 2(向上取整),问从起点到终点的分数的数学期望是多少?

思路:按照套路,先把这k个点按照pair的方式进行排序,设dp[i][j]为从起点到点i之前经过了至少j个减分点,到点i的数学期望。那么所有在它之前的可以向它转移的点向它转移。那么dp[i][j] = Σ(dp[u][j - 1] - dp[u][j]) * g(u, i)。其中g(u, i)是u, i之间没有限制条件的走法数目,用组合数学的方法计算即可。这样相当于是前面恰好走过j个点 + 可能走过大于一个点的方式转移过来,这样可以保证计数的不重不漏。

代码:

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define db double
#define LL long long
#define pii pair<int, int>
using namespace std;
const int maxn = 200010;
const LL mod = 1e9 + 7;
LL dp[2010][40];
pii a[2010];
LL v[maxn], inv[maxn];
LL qpow(LL x, LL y) {
LL ans = 1;
for (; y; y >>= 1) {
if(y & 1) ans = (ans * x) % mod;
x = (x * x) % mod;
}
return ans;
}
void init(int n) {
v[0] = 1;
for (int i = 1; i <= n; i++) {
v[i] = (v[i - 1] * i) % mod;
}
inv[n] = qpow(v[n], mod - 2);
for (int i = n - 1; i >= 0; i--) {
inv[i] = (inv[i + 1] * (i + 1)) % mod;
}
}
LL C(LL n, LL m) {
return (((v[n] * inv[m]) % mod) * inv[n - m]) % mod;
}
LL cal(int x, int y) {
LL tmp = abs(a[y].first - a[x].first), tmp1 = tmp + (a[y].second - a[x].second);
return C(tmp1, tmp);
}
LL b[50];
int main() {
int n, m, k, t;
scanf("%d%d%d%d", &n, &m, &k, &t);
init(n + m);
for (int i = 1; i <= k; i++) {
scanf("%d%d", &a[i].first, &a[i].second);
}
int lim = 0;
while(t > 1) {
b[++lim] = t;
t = (t + 1) / 2;
}
b[++lim] = 1;
b[lim + 1] = 1;
sort(a + 1, a + 1 + k);
k++;
a[k] = make_pair(n, m);
for (int i = 1; i <= k; i++) {
dp[i][0] = C(a[i].first + a[i].second - 2, a[i].first - 1);
}
LL ans = 0;
for (int j = 1; j <= lim; j++) {
for (int i = 1; i <= k; i++) {
for (int t = 1; t < i; t++) {
if(a[t].first <= a[i].first && a[t].second <= a[i].second) {
LL tmp1 = (dp[t][j - 1] - dp[t][j] + mod) % mod;
LL tmp2 = cal(t, i);
assert(tmp1 >= 0);
assert(tmp2 >= 0);
dp[i][j] += (tmp1 * tmp2) % mod;
dp[i][j] %= mod;
}
}
}
}
for (int i = 0; i <= lim; i++) {
ans = (ans + (((dp[k][i] - dp[k][i + 1] + mod) % mod) * b[i + 1]) % mod) % mod;
}
ans = (ans * qpow(C(n + m - 2, n - 1), mod - 2)) % mod;
printf("%lld\n", ans);
}

  

Codeforces 722E 组合数学 DP的更多相关文章

  1. codeforces 1194F (组合数学)

    Codeforces 11194F (组合数学) 传送门:https://codeforces.com/contest/1194/problem/F 题意: 你有n个事件,你需要按照1~n的顺序完成这 ...

  2. codeforces 722E Research Rover

    codeforces 722E Research Rover 题意 \(1e5*1e5\)的棋盘中有\(2000\)个坏点,初始给定一个值\(s(1<=s<=1e6)\).从棋盘左上角走到 ...

  3. 【uoj#22】[UR #1]外星人 组合数学+dp

    题目描述 给你一个长度为 $n$ 的序列 $\{a_i\}$ 和一个数 $x$ ,对于任意一个 $1\sim n$ 的排列 $\{p_i\}$ ,从 $1$ 到 $n$ 依次执行 $x=x\ \tex ...

  4. 【bzoj1925】[Sdoi2010]地精部落 组合数学+dp

    题目描述 传说很久以前,大地上居住着一种神秘的生物:地精. 地精喜欢住在连绵不绝的山脉中.具体地说,一座长度为 N 的山脉 H可分 为从左到右的 N 段,每段有一个独一无二的高度 Hi,其中Hi是1到 ...

  5. Codeforces Gym 100338H High Speed Trains 组合数学+dp+高精度

    原题链接:http://codeforces.com/gym/100338/attachments/download/2136/20062007-winter-petrozavodsk-camp-an ...

  6. D - Yet Another Problem On a Subsequence CodeForces - 1000D (DP,组合数学)

    D - Yet Another Problem On a Subsequence CodeForces - 1000D The sequence of integers a1,a2,-,aka1,a2 ...

  7. codeforces 659 G. Fence Divercity 组合数学 dp

    http://codeforces.com/problemset/problem/659/G 思路: f(i,0/1,0/1) 表示到了第i个,要被切的块开始了没有,结束了没有的状态的方案数 递推看代 ...

  8. Codeforces 886E Maximum Element 组合数学 + dp

    我们定义dp[ i ]表示长度为 i 的序列, 最后没有一个==k的时候返回的方案数, 也就是最后强制返回 i 的方案数. 我们能得到dp方程   dp[ i ] = sum(dp[ i - j - ...

  9. codeforces 869C The Intriguing Obsession【组合数学+dp+第二类斯特林公式】

    C. The Intriguing Obsession time limit per test 1 second memory limit per test 256 megabytes input s ...

随机推荐

  1. mysql服务设置远程连接

    一.前期准备 1.虚拟机/物理机    mysql环境(非本机)2.本机 navicat软件(验证远程连接) 二 .mysql配置 1.在远程主机的本机   使用root用户连接mysql mysql ...

  2. 英语单词vendors

    vendors 来源——https://www.docker.com/products/docker-hub Share and Collaborate with Docker Hub Docker ...

  3. python学习笔记(九)内置函数

    print(all([1,2,3,4]))#判断可迭代的对象里面的值是否都为真 True print(any([0,1,2,3,4]))#判断可迭代的对象里面的值是否有一个为真 True print( ...

  4. PHP实现跨服务器session共享的方法教程

    今天带来PHP实现跨服务器session共享的方法教程. 本文实例讲述了PHP实现cookie跨域session共享的方法.分享给大家供大家参考,具体如下: 做过web开发的小伙伴们都了解cookie ...

  5. 神坑 Resources.Load 不能实时加载TXT文件

    Resources.Load(fileName) as TextAsset; 这句话并不能实时加载文本文件,对文本文件进行修改之后,若是没有刷新的话,加载的还是之前的文件: 要实时读取文本文件还是要以 ...

  6. iOS逆向一个APP指令集

    一.脱壳获取.app文件 1.查询壳有没加密 otool -l  mac-o文件 | grep crypt 2.Clutch -i Clutch -d  num 3.脱壳后的位置 /private/v ...

  7. C#如何获取系统downloads和documents路径

    https://stackoverflow.com/questions/7672774/how-do-i-determine-the-windows-download-folder-path 如果你通 ...

  8. (\w+)\s*, \s*(\w+)

    \s表示空格 \w表示任何字符,字母数字下划线 _就表示下划线

  9. android7.0后对于file://的限制

    错误信息: 04-18 14:56:58.283  4440  4440 W System.err: android.os.FileUriExposedException: file:///stora ...

  10. 怎么查看keras 或者 tensorflow 正在使用的GPU

    查看keras认得到的GPU from keras import backend as K K.tensorflow_backend._get_available_gpus() Out[28]: [' ...