Eddy Walker

题目传送门

解题思路

因为走过所有的点就会停下来,又因为是从0出发的,所以当n>1时,在0停下来的概率为0,其他的为1/(n-1);

代码如下

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll; inline int read(){
int res = 0, w = 0; char ch = 0;
while(!isdigit(ch)){
w |= ch == '-', ch = getchar();
}
while(isdigit(ch)){
res = (res << 3) + (res << 1) + (ch ^ 48);
ch = getchar();
}
return w ? -res : res;
} template <typename A, typename B, typename C>
inline A fpow(A x, B p, C lyd){
A ans = 1;
for(; p; p >>= 1, x = 1LL * x * x % lyd)if(p & 1)ans = 1LL * x * ans % lyd;
return ans % lyd;
} ll get_inv(ll b, ll mod){
return fpow(b, mod - 2, mod);
} const int N = 100005;
const int mod = 1e9+7; int main()
{
int t;
cin >> t;
ll last = 1;
while(t --){
ll n, m;
cin >> n >> m;
ll ans;
if(m)
ans = 1 * get_inv(n - 1, mod) % mod;
else {
if(n > 1)
ans = 0;
else
ans = 1;
}
cout << ans * last % mod << endl;
last = ans * last % mod;
}
return 0;
}

最新文章

  1. Linux 如何查看修改DNS配置
  2. 带你玩转JavaWeb开发之六-mysql基本语法详解及实例(4)
  3. JIT动态编译器的原理与实现之Interpreter(解释器)的实现(三)
  4. HDU 1892 See you~
  5. jsoup使用选择器语法来查找元素
  6. Gora_百度百科
  7. 监听手机晃动(摇一摇)SensorEventListener
  8. hdu3664(递推dp)
  9. Objective-C MapKit的使用-LBS简单的租车主界面demo
  10. Mybatis中的模糊查询
  11. Python中pathlib模块
  12. Filebeat+Kafka+Logstash+ElasticSearch+Kibana搭建完整版
  13. linux下查看已安装的软件与卸载
  14. VO和DO转换(二) BeanUtils
  15. bzoj 2460 线性基
  16. MyEclipse 10 + OsChina GIt项目托管
  17. ABP框架系列之一:(Entity-实体)
  18. if判断比较详解
  19. excel技巧--多行排成单列
  20. jQuery操作DOM节点的方法总结

热门文章

  1. 栈Stack --- 数组实现
  2. HTML-参考手册: HTML 音频/视频
  3. webstorm 分屏
  4. dubbo超时原理以及解决方案
  5. NTFS文件系统
  6. libVEX学习
  7. 2019牛客多校第⑨场J Symmetrical Painting(思维,离散化)
  8. linux 下安装与使用
  9. Eureka 系列(07)服务注册与主动下线
  10. Javascript优点和缺点