Let Me Count The Ways(Kickstart Round H 2018)
2024-08-29 05:28:34
题目链接:https://code.google.com/codejam/contest/3324486/dashboard#s=p2
题目:
思路:
代码实现如下:
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pli;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL; #define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("D://code//in.txt", "r", stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0) const double eps = 1e-;
const int mod = ;
const int maxn = 2e5 + ;
const double pi = acos(-);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL; int t, n, m;
LL A[maxn], inv[maxn]; LL Mod_Pow(LL x, int n) {
LL res = ;
while(n) {
if(n & ) res = res * x % mod;
x = x * x % mod;
n >>= ;
}
return res;
} void init() {
A[] = ;
for(int i = ; i < maxn; i++) A[i] = (A[i-] * i) % mod;
inv[maxn-] = Mod_Pow(A[maxn-], mod - );
for(int i = maxn - ; i >= ; i--) {
inv[i] = inv[i+] * (i + ) % mod;
}
} int Com(int n, int m) {
if(n < || m < || m > n) return ;
if(m == || m == n) return ;
return ((A[n] * inv[n-m] % mod) * inv[m]) % mod;
} int main() {
#ifndef ONLINE_JUDGE
FIN;
#endif
init();
int icase = ;
scanf("%d", &t);
while(t--) {
scanf("%d%d", &n, &m);
LL sum = ;
for(int i = ; i <= m; i++) {
if(i % == ) {
sum = (sum + ((Com(m, i) * Mod_Pow(, i) % mod) * A[ * n - i]) % mod) % mod;
} else {
sum = (sum - ((Com(m, i) * Mod_Pow(, i) % mod) * A[ * n - i]) % mod + mod) % mod;
}
}
printf("Case #%d: %lld\n", ++icase, sum % mod);
}
return ;
}
最新文章
- CC countari &; 分块+FFT
- Spark调度管理(读书笔记)
- apache2错误日志在哪,可以看到php错误
- mongo里面根据对象字段的ID查询 db.Photo.find({&#39;owner.$id&#39;:ObjectId(&#39;xxxx&#39;)}) , 并且使用forEach循环修改查询的数据
- Daily Scrum – 1/4
- 改变placeholder颜色
- poj 2778 DNA Sequence ac自动机+矩阵快速幂
- php对象的高级特性
- jQuery循环给某个ID赋值
- CURL 宏定义列表
- img src某个php文件输出图片(回复更改图片readfile读取图片等)
- 玩转Web之Json(二)----jquery easy ui + Ajax +Json+SQL实现前后台数据交互
- jmeter出现卡死或内存溢出的解决方案
- 给hive的metastore做JVM优化
- 自动弹出pickerview
- 网络拓扑自动发掘之三层设备惯用的SNMP OID的含义
- centos7下zabbix安装与部署
- JavaWeb学习 (十五)————JSP指令
- luogu 4401 矿工配餐 多维dp
- c++基础:之封装