题目链接: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 ;
}

Let Me Count The Ways(Kickstart Round H 2018)的更多相关文章

  1. Kickstart Round H 2018

    打了ks好久都没有更新 诶,自己的粗心真的是没救了,A题大数据都能错 A #include <iostream> #include <cstdio> #include < ...

  2. Kickstart Round H 2019 Problem B. Diagonal Puzzle

    有史以来打得最差的一次kickstart竟然发生在winter camp出结果前的最后一次ks = = 感觉自己的winter camp要凉了 究其原因,无非自己太眼高手低,好好做B, C的小数据,也 ...

  3. Google Kickstart Round E 2018 B. Milk Tea

    太蠢了,,,因为初始化大数据没过,丢了10分,纪念一下这个错误 大概思路:先求出让损失值最小的排列,由已生成的这些排列,通过更改某一个位置的值,生成下一个最优解,迭代最多生成m+1个最优解即可,遍历求 ...

  4. Kickstart Round G 2018

    第一次打codejam....惨的一比,才A1.5题,感觉自己最近状态渣到姥姥家了,赶紧练练 A 模拟,注意0的问题 #include <iostream> #include <cs ...

  5. uva 357 Let Me Count The Ways(01背包)

    题目连接:357 - Let Me Count The Ways 题目大意:有5种硬币, 面值分别为1.5.10.25.50,现在给出金额,问可以用多少种方式组成该面值. 解题思路:和uva674是一 ...

  6. UVA 357 Let Me Count The Ways(全然背包)

    UVA 357 Let Me Count The Ways(全然背包) http://uva.onlinejudge.org/index.php?option=com_onlinejudge& ...

  7. UVA.357 Let Me Count The Ways (DP 完全背包)

    UVA.357 Let Me Count The Ways (DP 完全背包) 题意分析 与UVA.UVA.674 Coin Change是一模一样的题.需要注意的是,此题的数据量较大,dp数组需要使 ...

  8. 2019 google kickstart round A

    第一题: n个人,每个人有一个对应的技能值s,现在要从n个人中选出p个人,使得他们的技能值相同. 显然,如果存在p个人的技能值是相同的,输出0就可以了.如果不存在,就要找出p个人,对他们进行训练,治他 ...

  9. UVa 357 - Let Me Count The Ways

    题目大意:也是硬币兑换问题,与147.674用同样的方法即可解决. #include <cstdio> #include <cstring> #define MAXN 3000 ...

随机推荐

  1. 如何获取app的activity

    (一) 本机安装appium的环境后,在cmd中输入:adb logcat>D:/log.log (二)真题连接电脑或在虚拟机中启动被测试app (三)直接查看d盘的log.log即可从来里面找 ...

  2. 爬虫学习之-scrapy交互式命令

    scrapy shell https:///www.baidu.com  会启动爬虫请求网页 view(response) 会在浏览器打开请求到的临时文件 response.xpath("/ ...

  3. 【问底】王帅:深入PHP内核(一)——弱类型变量原理探究

    来源:CSDN    http://www.csdn.net/article/2014-09-15/2821685-exploring-of-the-php 作者:王帅 摘要:PHP作为一门简单而强大 ...

  4. JS 把数组按倒序排列

    var achearr=[1,2,3,4]; var bchearr=[]; //方法1: for (var i = 0; i <=achearr.length;i++) { bchearr.p ...

  5. sklearn-特征工程之特征选择

    title: sklearn-特征工程之特征选择 date: 2016-11-25 22:49:24 categories: skearn tags: sklearn --- 抄袭/参考资料 使用sk ...

  6. screen.height && screen.width

    screen.height && screen.width how to get window max width in js screen.height; screen.width; ...

  7. 计算机网络【7】—— TCP的精髓

    参考文献: http://blog.chinaunix.net/uid-26275986-id-4109679.html TCP协议作为一个可靠的面向流的传输协议,其可靠性和流量控制由滑动窗口协议保证 ...

  8. php的数组转为对象

    有时候数组要转为对象操作,用对象的指向操作符,有两种方法 方法一: $arr=['a'=>10,'b'=>100,'c'=>'Hello']; $obj=(Object)$arr; ...

  9. 阿里云上部署了zabbix,突然无法收到报警邮件的解决办法

    在阿里云上部署了zabbix,一直能正常接收到zbx发来的报警邮件(报警邮箱是163的),不知是什么原因,突然无法接收到报警邮件了. 但在服务器上手动执行echo "hello"| ...

  10. git更换 拉取推送地址

    更换:git remote set-url originhttp://git.caomall.cn/sucry/mouse.git」