[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亲自实现了一个,需要学习 ...
随机推荐
- kindle转换工具-calibre
kindle转换工具 calibre https://calibre-ebook.com/download_windows
- GHOST分区丢失只剩C盘
很多人装系统时会经常会使用GHOST来恢复自己的系统,当WINDOWS系统出现意外时,再用GHOST的“From Image to 分区”来对系统进行恢复,这样就可以省去繁琐耗时的重新安装操作系统的工 ...
- Spring的Aspect切面类不能拦截Controller中的方法
根本原因在于<aop:aspectj-autoproxy />这句话是在spring的配置文件内,还是在springmvc的配置文件内.如果是在spring的配置文件内,则@Control ...
- tomcat apr
背景 前面也提过了,这次是在linux下的实验.不要信广告,要看疗效.其实起不了都大作用. 转载 开始安装~ 1)安装apr tar zxvf apr-1.4.2.tar cd ...
- 026_关于shell中的特殊变量$0 $n $* $@ $! $?
一. $n:获取当前执行的shell脚本的第N个参数,n=1..9,当n为0时表示脚本的文件名,如果n大于9,用大括号括起来like${10}. $*:获取当前shell的所有参数,将所有的命令行参数 ...
- (常用)subprocess模块 详情官方
subprocess包中定义有数个创建子进程的函数,这些函数分别以不同的方式创建子进程,所以我们可以根据需要来从中选取一个使用.另外subprocess还提供了一些管理标准流(standard str ...
- 目标检测的图像特征提取之(一)HOG特征(转)
看过很多介绍HOG的博文,讲的最清楚的是这位博主:http://blog.csdn.net/zouxy09/article/details/7929348 代码如下: #include <ope ...
- vue渲染时对象里面的对象的属性提示undefined,但渲染成功
场景: 从后台请求的数据结构如下: 我的list是对象,而comment又是list里的对象,渲染成功了,却报如下错: 解决办法: 添加一个:v-if
- LeetCode(35):搜索插入位置
Easy! 题目描述: 给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引.如果目标值不存在于数组中,返回它将会被按顺序插入的位置. 你可以假设数组中无重复元素. 示例 1: 输入: [1 ...
- php-fpm 配置文件检测
用过 Nginx 的兄弟都知道,修改 Nginx 配置文件之后,可以使用 nginx -t 来检测配置文件是否有语法错误. 今天配置 opcache 的时候,发现 php-fpm 也可以检测 php- ...