Let Me Count The Ways(Kickstart Round H 2018)
题目链接: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)的更多相关文章
- Kickstart Round H 2018
打了ks好久都没有更新 诶,自己的粗心真的是没救了,A题大数据都能错 A #include <iostream> #include <cstdio> #include < ...
- Kickstart Round H 2019 Problem B. Diagonal Puzzle
有史以来打得最差的一次kickstart竟然发生在winter camp出结果前的最后一次ks = = 感觉自己的winter camp要凉了 究其原因,无非自己太眼高手低,好好做B, C的小数据,也 ...
- Google Kickstart Round E 2018 B. Milk Tea
太蠢了,,,因为初始化大数据没过,丢了10分,纪念一下这个错误 大概思路:先求出让损失值最小的排列,由已生成的这些排列,通过更改某一个位置的值,生成下一个最优解,迭代最多生成m+1个最优解即可,遍历求 ...
- Kickstart Round G 2018
第一次打codejam....惨的一比,才A1.5题,感觉自己最近状态渣到姥姥家了,赶紧练练 A 模拟,注意0的问题 #include <iostream> #include <cs ...
- uva 357 Let Me Count The Ways(01背包)
题目连接:357 - Let Me Count The Ways 题目大意:有5种硬币, 面值分别为1.5.10.25.50,现在给出金额,问可以用多少种方式组成该面值. 解题思路:和uva674是一 ...
- UVA 357 Let Me Count The Ways(全然背包)
UVA 357 Let Me Count The Ways(全然背包) http://uva.onlinejudge.org/index.php?option=com_onlinejudge& ...
- UVA.357 Let Me Count The Ways (DP 完全背包)
UVA.357 Let Me Count The Ways (DP 完全背包) 题意分析 与UVA.UVA.674 Coin Change是一模一样的题.需要注意的是,此题的数据量较大,dp数组需要使 ...
- 2019 google kickstart round A
第一题: n个人,每个人有一个对应的技能值s,现在要从n个人中选出p个人,使得他们的技能值相同. 显然,如果存在p个人的技能值是相同的,输出0就可以了.如果不存在,就要找出p个人,对他们进行训练,治他 ...
- UVa 357 - Let Me Count The Ways
题目大意:也是硬币兑换问题,与147.674用同样的方法即可解决. #include <cstdio> #include <cstring> #define MAXN 3000 ...
随机推荐
- Java中的多线程科普
如果对什么是线程.什么是进程仍存有疑惑,请先Google之,因为这两个概念不在本文的范围之内. 用多线程只有一个目的,那就是更好的利用cpu的资源,因为所有的多线程代码都可以用单线程来实现.说这个话其 ...
- 开发模式 MVC、MVP、MVVM和MVX框架模式
MVX框架模式的了解 MVX框架模式:MVC+MVP+MVVM 1.MVC: Model(模型)+View(视图)+controller(控制器),主要是基于分层的目的,让彼此的职责分开.View通过 ...
- Reverse Words in a String II
Given an input string, reverse the string word by word. A word is defined as a sequence of non-space ...
- c++ 替换修改一个文件夹下的所有文件的文件名
代码简洁,亲测可用. 1,首先来获取(输出)一个文件夹中所有的文件名 void getFiles(string path, vector<string>& files) { //文 ...
- UVA10047_The Monocycle
这题....有点奇葩,但是不难. 在矩形方阵里,某人可以往前走或者左拐右拐.都需要消耗一个单位时间. 问某人从一个点走向另一个点的最短时间,并且走过的路程是5的倍数. 由于n,m都小,直接f[n][m ...
- selenium+python定位元素的方法及使用
selenium的八种定位方法 By.ID 通过id定位 By.CLASS_NAME 通过className定位 By.CSS_SELECTOR 通过CSS定位 By.LINK_TEXT 通过link ...
- LINQ 模糊搜索
IList<entity> ls = new List<entity>(); ls = (from k in ls where k.Name.Contains("sa ...
- Android中Selector的用法(改变ListView和Button的默认背景)
Android中的Selector的用法 http://blog.csdn.net/shakespeare001/article/details/7788400#comments Android中的S ...
- bzoj4035【HAOI2015】数组游戏
题目描述 有一个长度为N的数组,甲乙两人在上面进行这样一个游戏:首先,数组上有一些格子是白的,有一些是黑的.然 后两人轮流进行操作.每次操作选择一个白色的格子,假设它的下标为x.接着,选择一个大小在1 ...
- Linux运维六:用户管理及用户权限设置
Linux 系统是一个多用户多任务的分时操作系统,任何一个要使用系统资源的用户,都必须首先向系统管理员申请一个账号,然后以这个账号的身份进入系统.用户的账号一方面可以帮助系统管理员对使用系统的用户进行 ...