B - RGB Coloring

求ax + by = k (0<=x<=n && 0<=y<=n)的方案数,最后乘上C(n, x)*C(n,y)

代码:

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pii pair<int, int>
#define piii pair<int,pii>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = 3e5 + ;
const int MOD = ;
int inv[N], fac[N];
LL q_pow(LL n, LL k) {
LL ans = ;
while(k) {
if(k&) ans = (ans * n) % MOD;
n = (n * n) % MOD;
k >>= ;
}
return ans;
}
void init() {
fac[] = ;
for (int i = ; i < N; i++) fac[i] = (1LL * fac[i-] * i) % MOD;
inv[N-] = q_pow(fac[N-], MOD - );
for (int i = N-; i >= ; i--) inv[i] = (1LL * inv[i+] * (i+)) % MOD;
}
LL C(int n, int k) {
return 1LL* fac[n] * inv[n-k] % MOD * inv[k] % MOD;
}
int main() {
int n, a, b;
LL k;
init();
scanf("%d%d%d%lld", &n, &a, &b, &k);
LL ans = ;
for (int x = ; x <= n; x++) {
LL t = k - 1LL*x*a;
if(t < ) break;
if(t%b) continue;
LL y = t/b;
if(y > n) continue;
ans += (C(n, x)*C(n, y)) % MOD;
ans %= MOD;
}
printf("%lld\n", ans);
return ;
}

AtCoder Grand Contest 025 B - RGB Coloring的更多相关文章

  1. AtCoder Grand Contest 030 (AGC030) C - Coloring Torus 构造

    原文链接https://www.cnblogs.com/zhouzhendong/p/AGC030C.html 题解 才发现当时是被题意杀了. 当时理解的题意是“对于任意的 (i,j) ,颜色 i 和 ...

  2. AtCoder Grand Contest 026 D - Histogram Coloring

    一列中有两个连续的元素,那么下一列只能选择选择正好相反的填色方案(因为连续的地方填色方案已经确定,其他地方也就确定了) 我们现将高度进行离散化到Has数组中,然后定义dp数组 dp[i][j] 表示前 ...

  3. AtCoder Grand Contest 025 Problem D - Choosing Points

    题目大意:输入$n,d1,d2$,你要找到$n^2$个整点 x, y 满足$0 \leqslant x, y<2n$.并且找到的任意两个点距离,既不是$\sqrt{d1}$,也不是 $\sqrt ...

  4. AtCoder Grand Contest #026 C - String Coloring

    Time Limit: 3 sec / Memory Limit: 1024 MB Score : 600600 points Problem Statement You are given a st ...

  5. AtCoder Grand Contest 012

    AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...

  6. AtCoder Grand Contest 011

    AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...

  7. AtCoder Grand Contest 031 简要题解

    AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...

  8. AtCoder Grand Contest 010

    AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...

  9. AtCoder Grand Contest 009

    AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include< ...

随机推荐

  1. Jira客户端

    github地址 https://github.com/rcarz/jira-client 使用 1)私服 <!-- https://mvnrepository.com/artifact/net ...

  2. Linux 编程简单示例代码

    Linux进程管理 编辑a.c 文件 #include <stdio.h> #include <unistd.h> int main() { printf( "Mes ...

  3. 原来Github上的README.md文件这么有意思——Markdown语言详解(sublime text2 版本)

    一直想学习 Markdown 语言,想起以前读的一篇 赵凯强 的 博客 <原来Github上的README.md文件这么有意思——Markdown语言详解>,该篇博主 使用的是Mac系统, ...

  4. Codeforces 844D Interactive LowerBound - 随机化

    This is an interactive problem. You are given a sorted in increasing order singly linked list. You s ...

  5. uniGUI试用笔记(三)

    uniGUI下的MessageDlg使用发生了变化,最大的特点是: 1.成为了uniGUIForm的成员函数: 2.变成过程(procedure)了,也就是没有返回值了,使得程序不再具有线程阻塞性. ...

  6. FireMonkey 源码学习(5)

    (5)UpdateCharRec 该函数的源码分析如下: procedure TTextLayoutNG.UpdateCharRec(const ACanvas: TCanvas; NeedBitma ...

  7. tp框架中的一些疑点知识-1

    tp默认的编码是utf-8 Runtime中的Cache和Logs都是分模块的,因为在应用app下可以有多个模块,但是 公共模块和Runtime模块只有一个, 所以, Runtime要包含各个模块的内 ...

  8. 再次安装fedora23的一些遗留问题的解决

    当你习惯了某个版本后, 就不想再更换了. 安装fedora23的磁盘空间 获得? 在安装新的fedora23 的时候, 原来的磁盘没有清空, 于是 就 have not enough free apa ...

  9. Hyper

    https://github.com/zeit/hyper https://gist.github.com/coco-napky/404220405435b3d0373e37ec43e54a23 Ho ...

  10. cat查看文件以及sed查看指定行数

    https://unix.stackexchange.com/questions/288521/with-the-linux-cat-command-how-do-i-show-only-certai ...