AtCoder Grand Contest 025 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的更多相关文章
- AtCoder Grand Contest 030 (AGC030) C - Coloring Torus 构造
原文链接https://www.cnblogs.com/zhouzhendong/p/AGC030C.html 题解 才发现当时是被题意杀了. 当时理解的题意是“对于任意的 (i,j) ,颜色 i 和 ...
- AtCoder Grand Contest 026 D - Histogram Coloring
一列中有两个连续的元素,那么下一列只能选择选择正好相反的填色方案(因为连续的地方填色方案已经确定,其他地方也就确定了) 我们现将高度进行离散化到Has数组中,然后定义dp数组 dp[i][j] 表示前 ...
- AtCoder Grand Contest 025 Problem D - Choosing Points
题目大意:输入$n,d1,d2$,你要找到$n^2$个整点 x, y 满足$0 \leqslant x, y<2n$.并且找到的任意两个点距离,既不是$\sqrt{d1}$,也不是 $\sqrt ...
- 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 ...
- AtCoder Grand Contest 012
AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...
- AtCoder Grand Contest 011
AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...
- AtCoder Grand Contest 031 简要题解
AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...
- AtCoder Grand Contest 010
AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...
- AtCoder Grand Contest 009
AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include< ...
随机推荐
- fjwc2019 D3T2 送分题
#185. 「2019冬令营提高组」送分题 这是原题..... P3615 如厕计划 手推一推你发现,显然男性不能多于女性. 然后你或许可以发现一个神奇的性质. 对于每个序列,我们记$M$为$1$,$ ...
- 【题解】Luogu P2572 [SCOI2010]序列操作
原题传送门:P2572 [SCOI2010]序列操作 这题好弱智啊 裸的珂朵莉树 前置芝士:珂朵莉树 窝博客里对珂朵莉树的介绍 没什么好说的自己看看吧 操作1:把区间内所有数推平成0,珂朵莉树基本操作 ...
- centOS 7 gitlab安装
https://www.cnblogs.com/chenfool/p/7689438.html 配置阿里巴巴 yum 源 wget -O /etc/yum.repos.d/CentOS-Base.re ...
- was清除项目缓存数据
步骤 彻底清理删除后的项目缓存 删除${WAS_HOME}\AppServer\profiles\AppSrv01\config\cells\xxxxxNode01Cell/applications/ ...
- CentOS7下Docker中构建可以自动发布到项目的Tomcat容器
步骤 下载镜像 搜索相应的镜像文件:docker search 'tomcat' 如下 下载镜像:docker pull tomcat:7,如下图 PS:后面的数字代表tomcat的版本,可以自己选择 ...
- Eclipse之maven插件link方式安装
maven是开发人员要具备的必不可少的技能之一.在使用eclipse进行开发时,我们需要安装maven插件,网上有很多教程,但是有些教程写的太过模糊.在此,我将自己的安装方法总结一下,尽量细致. 前提 ...
- emmc和ssd的区别【转】
本文转载自:https://blog.csdn.net/hawk_lexiang/article/details/78228789 emmc和ssd eMMC和SSD主要是满足不同需求而发展出来的NA ...
- (转)开源项目miaosha(上)
石墨文档:https://shimo.im/docs/iTDoZs4CVfICgSfV/ (二期)19.开源秒杀项目miaosha解读(上) [课程19]几张图.xmind0.6MB [课程19]开源 ...
- X-Pack for the Elastic Stack [6.2] » Securing the Elastic Stack »Setting Up User Authentication
https://www.elastic.co/guide/en/x-pack/current/setting-up-authentication.html Active Directory User ...
- win32 汇编学习(2):消息框
这一次,我们将用汇编语言写一个 Windows 程序,程序运行时将弹出一个消息框并显示"你好,我的第一个Win32汇编程序". 理论知识 Windows 为编写应用程序提供了大量的 ...