[AGC025B]RGB Coloring
[AGC025B]RGB Coloring
题目大意:
有\(n(n\le3\times10^5)\)个格子,每个格子可以选择涂成红色、蓝色、绿色或不涂色,三种颜色分别产生\(a,b,a+b(a,b\le3\times10^5)\)的收益。问有多少种涂色方案使得总收益为\(k(k\le18\times10^{10})\)。
思路:
涂绿色就相当于同时涂了红色和蓝色,因此枚举红色出现次数\(i\)和蓝色出现次数\(j\)。答案就是\(\displaystyle\sum_{\substack{0\le i,j\le n\\ai+bj\le k}}{n\choose i}{n\choose j}\)。
时间复杂度\(\mathcal O(n)\)。
源代码:
#include<cstdio>
#include<cctype>
#include<algorithm>
typedef long long int64;
inline int64 getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int64 x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return x;
}
const int N=3e5+1,mod=998244353;
int fac[N],ifac[N];
void exgcd(const int &a,const int &b,int &x,int &y) {
if(!b) {
x=1,y=0;
return;
}
exgcd(b,a%b,y,x);
y-=a/b*x;
}
inline int inv(const int &x) {
int ret,tmp;
exgcd(x,mod,ret,tmp);
return (ret%mod+mod)%mod;
}
inline int power(int a,int k) {
int ret=1;
for(;k;k>>=1) {
if(k&1) ret=(int64)ret*a%mod;
a=(int64)a*a%mod;
}
return ret;
}
inline int C(const int &n,const int &m) {
return (int64)fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int main() {
int n=getint(),a=getint(),b=getint();
int64 k=getint();
for(register int i=fac[0]=1;i<=n;i++) {
fac[i]=(int64)fac[i-1]*i%mod;
}
ifac[n]=inv(fac[n]);
for(register int i=n;i>=1;i--) {
ifac[i-1]=(int64)ifac[i]*i%mod;
}
int ans=0;
for(register int i=0;i<=n&&(int64)a*i<=k;i++) {
if((k-(int64)a*i)%b!=0) continue;
const int64 j=(k-(int64)a*i)/b;
if(j>n) continue;
(ans+=(int64)C(n,i)*C(n,j)%mod)%=mod;
}
printf("%d\n",ans);
return 0;
}
[AGC025B]RGB Coloring的更多相关文章
- AtCoder Grand Contest 025 B - RGB Coloring
B - RGB Coloring 求ax + by = k (0<=x<=n && 0<=y<=n)的方案数,最后乘上C(n, x)*C(n,y) 代码: #i ...
- AGC 025 B - RGB Coloring
B - RGB Coloring Time limit : 2sec / Memory limit : 1024MB Score : 700 points Problem Statement Taka ...
- 【AtCoder】AGC025题解
A - Digits Sum 枚举即可 代码 #include <bits/stdc++.h> #define fi first #define se second #define pii ...
- AGC025简要题解
AGC025简要题解 B RGB Coloring 一道简单题,枚举即可. C Interval Game 考虑可以进行的操作只有两种,即左拉和右拉,连续进行两次相同的操作是没有用的. 左拉时肯定会选 ...
- 【AGC025B】RGB Color
[AGC025B]RGB Color 题面描述 Link to Atcoder Link to Luogu Takahashi has a tower which is divided into \( ...
- RGB,CMYK,HSB各种颜色表示的转换 C#语言
Introduction Why an article on "colors"? It's the same question I asked myself before writ ...
- html5中canvas的使用 获取鼠标点击页面上某点的RGB
1.html5中的canvas在IE9中可以跑起来.在IE8则跑不起来,这时候就需要一些东西了. 我推荐这种方法,这样显得代码不乱. <!--[if lt IE9]> <script ...
- 【视频处理】YUV与RGB格式转换
YUV格式具有亮度信息和色彩信息分离的特点,但大多数图像处理操作都是基于RGB格式. 因此当要对图像进行后期处理显示时,需要把YUV格式转换成RGB格式. RGB与YUV的变换公式如下: YUV(25 ...
- Applying vector median filter on RGB image based on matlab
前言: 最近想看看矢量中值滤波(Vector median filter, VMF)在GRB图像上的滤波效果,意外的是找了一大圈却发现网上没有现成的code,所以通过matab亲自实现了一个,需要学习 ...
随机推荐
- Linux内存管理5---物理内存管理
1.前言 本文所述关于内存管理的系列文章主要是对陈莉君老师所讲述的内存管理知识讲座的整理. 本讲座主要分三个主题展开对内存管理进行讲解:内存管理的硬件基础.虚拟地址空间的管理.物理地址空间的管理. 本 ...
- Python 优雅获取本机 IP 方法【转】
转自:https://www.cnblogs.com/lfxiao/p/9672975.html 见过很多获取服务器本地IP的代码,个人觉得都不是很好,例如以下这些 不推荐:靠猜测去获取本地IP方法 ...
- Caching漫谈--关于Cache的几个理论
如今缓存是随处可见了,如果你的程序还没有使用到缓存,那可能是你的程序并发量很低,或对实时性要求很低.我们公司的ERP在显示某些报表时,每次打开都需要花上几分钟的时间,假如搜索引擎也是这么慢,我想这家搜 ...
- DataSnap ClientdataSet 三层中主从表的操作
非原创 摘自:http://hi.baidu.com/yagzh2000/blog/item/fc69df2cb9845de78b139946.html三层中主从表的操作(删除.新增.修改)一定要在 ...
- 分布式系列 - dubbo服务telnet命令【转】
dubbo服务发布之后,我们可以利用telnet命令进行调试.管理.Dubbo2.0.5以上版本服务提供端口支持telnet命令,下面我以通过实例抛砖引玉一下: 1.连接服务 测试对应IP和端口下的d ...
- 一步步实现windows版ijkplayer系列文章之六——SDL2源码分析之OpenGL ES在windows上的渲染过程
一步步实现windows版ijkplayer系列文章之一--Windows10平台编译ffmpeg 4.0.2,生成ffplay 一步步实现windows版ijkplayer系列文章之二--Ijkpl ...
- zookeeper3.4.6配置实现自动清理日志
在使用zookeeper过程中,我们知道,会有dataDir和dataLogDir两个目录,分别用于snapshot和事务日志的输出(默认情况下只有dataDir目录,snapshot和事务日志都保存 ...
- [转]MySQL中函数CONCAT及GROUP_CONCAT
一.CONCAT()函数 CONCAT()函数用于将多个字符串连接成一个字符串. 使用数据表Info作为示例,其中SELECT id,name FROM info LIMIT 1;的返回结果为 +-- ...
- vue系列之webstrom的设置
1.安装vue插件,方法 Setting->Plugins,点击Plugins,在右边输入vue,找到相应插件,然后安装 2.创建vue模板 注意红圈里面的 3.设置vue文件支持的样式 注意: ...
- Highcharts 使用
官网:https://www.hcharts.cn/ api:https://api.hcharts.cn/highcharts 效果 html代码 <div id="containe ...