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. Python3 Pandas的DataFrame数据的增、删、改、查

    Python3 Pandas的DataFrame数据的增.删.改.查 一.DataFrame数据准备 增.删.改.查的方法有很多很多种,这里只展示出常用的几种. 参数inplace默认为False,只 ...

  2. SSM项目开发中的实体定义以及MySQL表格设计

    话不多说,下面表格是项目开发中用到的实体集以及表格Name 实体创建     表格创建 Area 区域 Area 实体 areaId areaName priority createTime last ...

  3. JQuery的ajax方法获取返回值得到了值还包含了不要的html源码 (Ajax相关知识)

    因为后台使用了response.Write():这个方法,当输出完了以后,没有结束掉会继续输出,所以需要用到response.End():这样问题就解决了 jquery的ajax 除了通过url传值, ...

  4. (转) Face-Resources

        本文转自:https://github.com/betars/Face-Resources Face-Resources Following is a growing list of some ...

  5. 【Net Core】DNX概述

    1. 什么是.NET执行环境 ? .NET Execution Environment(DNX) 是一个SDK 和运行时环境,它包含所有的你需要创建和运行.net应用程序的组件.它提供一个主机进程,C ...

  6. ZooKeeper分布式过程协同技术详解2——了解ZooKeeper

    这个服务如何实现这些协作方面的原语? ZooKeeper基础

  7. .NET 介绍

    In order to continue our effort of being modular and well factored we don’t just provide the entire ...

  8. dRMT: Disaggregated Programmable Switching, SIGCOMM17

    Reference: dRMT, SIGCOMM 2017 今年的SIGCOMM17会议上,Cisco System和MIT的团队针对RMT模型现有的问题,合作发表了这篇"dRMT: Dis ...

  9. Anaconda 安装后配置环境变量

    Anaconda 安装后在 cmd 中运算 python 无效, 是环境变量没有生效.正常安装需要有三个,配置好就行. D:\xwapp\ProgramData\Anaconda3 D:\xwapp\ ...

  10. 小文笔记 - phantomjs

    小文笔记 - phantomjs 视频推荐: http://www.intalesson.com/compedium/phantom 2017-05-13 第一节:安装 Windows安装: 下载解压 ...