Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)E. Research Rover (容斥Lucas)
来源:互联网 发布:倩女幽魂手游 mac登陆 编辑:程序博客网 时间:2024/06/10 16:57
题意:
从(1,1)通过最短路径走到(n,m),能量值为s,其中有k个特殊点,每经过一个特殊点能力值就会变成(s+1)/2,问最后能力值的期望值。
思路:
容易发现s减小的速度是很快的,最多20次就会变成1,因此我们算出经过0,1,2…20个特殊点的方案数,剩下的方案能力值都是1了。
首先考虑经过0个特殊点的方案数,就是这个题,是个很经典的容斥了,首先按经过的顺序排序,如果从点a可以走到点b,那a就在b前面,然后就可以算出从(1,1)走到点(x,y)且不经过其他点的方案数,推一下就可以算出从(1,1)走到点(n,m)不经过特殊点的方案数了。
从(1,1)通过最短路径走到(n,m),能量值为s,其中有k个特殊点,每经过一个特殊点能力值就会变成(s+1)/2,问最后能力值的期望值。
思路:
容易发现s减小的速度是很快的,最多20次就会变成1,因此我们算出经过0,1,2…20个特殊点的方案数,剩下的方案能力值都是1了。
首先考虑经过0个特殊点的方案数,就是这个题,是个很经典的容斥了,首先按经过的顺序排序,如果从点a可以走到点b,那a就在b前面,然后就可以算出从(1,1)走到点(x,y)且不经过其他点的方案数,推一下就可以算出从(1,1)走到点(n,m)不经过特殊点的方案数了。
可以发现这个题就是要算恰好经过k个点的方案数,按照上面的思路来就行。
#include <iostream>#include <stdio.h>#include <algorithm>#include <string.h>#include <vector>using namespace std;typedef long long ll;typedef pair<int,int> pii;const int N = 2e5+5;ll fac[N], invfac[N];const ll mod = 1e9+7;ll qpow(ll a, ll k) { ll res = 1; while(k) { if(k&1) res = (res*a)%mod; a = (a*a)%mod; k >>= 1; } return res;}void init(){ fac[0] = 1, invfac[0] = 1; fac[1] = 1, invfac[1] = 1; for(ll x = 2; x < N; ++x){ fac[x] = (fac[x-1]*x)%mod; invfac[x] = qpow(fac[x], mod-2); }}ll C(int n, int m) { if(n < 0 || m < 0 || n < m) return 0; else if(n == m) return 1; else return fac[n]*invfac[m]%mod*invfac[n-m]%mod;}pii p[2005];inline bool cmp(const pii& a, const pii& b) { return a.first+a.second < b.first+b.second;}ll cal(pii a, pii b) { int x = b.first-a.first, y = b.second-a.second; return C(x+y, x);}ll dp[2005][25];int main(int argc, const char * argv[]) { init(); int n, m, k, s; scanf("%d%d%d%d", &n, &m, &k, &s); for(int i = 1; i <= k; ++i) { scanf("%d %d", &p[i].first, &p[i].second); } p[0] = pii(1, 1); p[++k] = pii(n, m); sort(p, p+k+1, cmp); dp[0][0] = 1, dp[1][0] = cal(p[0], p[1]); for(int i = 2; i <= k; ++i) { dp[i][0] = cal(p[0], p[i]); for(int j = 1; j < i; ++j) { dp[i][0] = (dp[i][0]-dp[j][0]*cal(p[j], p[i])%mod+mod)%mod; } } for(int i = 1; i <= 20; ++i) { for(int j = 0; j <= k; ++j) { dp[j][i] = cal(p[0], p[j]); for(int l = 0; l < i; ++l) { dp[j][i] = (dp[j][i]-dp[j][l]+mod)%mod; } for(int l = 1; l < j; ++l) { dp[j][i] = (dp[j][i]-dp[l][i]*cal(p[l], p[j])%mod+mod)%mod; } } } ll ans = 0, tot = cal(p[0], p[k]); for(int i = 0; i <= 20; ++i, s = (s+1)/2) { ans = (ans+dp[k][i]*s%mod)%mod; tot = (tot-dp[k][i]+mod)%mod; } ans = (ans+tot)%mod; ans = ans*qpow(cal(p[0], p[k]), mod-2)%mod; printf("%lld\n", ans); return 0;}
0 0
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)E. Research Rover (容斥Lucas)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) E
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) -- A. Broken Clock (贪心)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) -- B. Verse Pattern(水题)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) -- D. Generating Sets(贪心)
- Codeforces Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) 部分题解
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) [D] Destroying Array
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)D. Generating Sets(贪心)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C 并查集
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) F
- codeforeces722 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)F. Cyclic Cipher
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D. Generating Sets 贪心
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) -- C. Destroying Array (并查集)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C. Destroying Array(并查集)
- SwipeRefreshLayout添加listview下拉冲突问题
- iOS逆向工程
- Cursor源码梳理
- Linux设置静态IP
- 如何安装 sass
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)E. Research Rover (容斥Lucas)
- Timer和TimerTask详解
- 解决spark-shell执行官方sparkstreaming 报 only one sparkcontext maybe running in this jvm的错误
- I/O复用之epoll简介
- CircleView轻量级显示圆形,支持更多属性
- 【转载】互联网高级测试工程师至少具备的能力
- Access restriction:The type JPEGCodec is not accessible due to restriction on re
- coding interview guide-仅用递归函数和栈操作逆序一个栈-c++实现
- 提交应用到iTunes Connect时构建版本“正在处理”后直接消失