[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亲自实现了一个,需要学习 ...
随机推荐
- UML和模式应用1: 面向对象的分析与设计
1.基本术语说明 items note OOA/D 面向对象的分析与设计 UML 描述.构造和文档化系统制品的可视化语言 模式 问题解决方案的公式 2. 本书的主要内容 本书的主旨是对应用了UML和 ...
- SharePoint 2013 Workflow Manager 1.0 远程服务器返回错误: (400) 错误的请求。 不支持查询字符串中的 api-version
环境: Windows Server 2012 R2 Standard SharePoint Server 2013 with sp1 通过Web 平台安装程序 5.0,已安装 Workflow Ma ...
- ORACLE 利用SCN恢复误delete的表
--kg是误删除的表 SQL> select count(*) from kg; COUNT(*) ---------- 820861 SQL> delete from kg; ...
- Vue+ajax的使用小结
js var vue = new Vue({ el:"#vueid", data:{ selectById : "", }, methods:{ yourMet ...
- Android系统信息(内存、cpu、sd卡、电量、版本)获取
Android系统信息(内存.cpu.sd卡.电量.版本)获取 /*APPInfo.java*/ public class AppInfo { private String appLable; pri ...
- 02-第一个JavaScript代码
在页面中,我们可以在body标签中放入<script type=”text/javascript”></script>标签对儿,<script type=”text/ja ...
- sklearn,交叉验证中的分层抽样
StratifiedKFold用法类似Kfold,但是他是分层采样,确保训练集,测试集中各类别样本的比例与原始数据集中相同. 例子: import numpy as np from sklearn.m ...
- Mac下brew安装与配置mysql
一.打开mac控制台 $ brew install mysql 二.启动mysql服务 $ mysql.server start 三.初始化mysql配置 1 rainMacBook-Pro:~ co ...
- js高阶函数map和reduce
map 举例说明,比如我们有一个函数f(x)=x2,要把这个函数作用在一个数组[1, 2, 3, 4, 5, 6, 7, 8, 9]上,就可以用map实现如下: 由于map()方法定义在JavaScr ...
- vue构建项目全过程
1.node版本请更新到6.9.X版本以上,不然npm依赖会出问题 2.命令行里运行npm install --global vue-cli 3.npm install --global webpac ...