2019牛客多校第二场A-Eddy Walker
2024-10-07 18:55:30
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;
}
最新文章
- Linux 如何查看修改DNS配置
- 带你玩转JavaWeb开发之六-mysql基本语法详解及实例(4)
- JIT动态编译器的原理与实现之Interpreter(解释器)的实现(三)
- HDU 1892 See you~
- jsoup使用选择器语法来查找元素
- Gora_百度百科
- 监听手机晃动(摇一摇)SensorEventListener
- hdu3664(递推dp)
- Objective-C MapKit的使用-LBS简单的租车主界面demo
- Mybatis中的模糊查询
- Python中pathlib模块
- Filebeat+Kafka+Logstash+ElasticSearch+Kibana搭建完整版
- linux下查看已安装的软件与卸载
- VO和DO转换(二) BeanUtils
- bzoj 2460 线性基
- MyEclipse 10 + OsChina GIt项目托管
- ABP框架系列之一:(Entity-实体)
- if判断比较详解
- excel技巧--多行排成单列
- jQuery操作DOM节点的方法总结