AGC 025 B - RGB Coloring
B - RGB Coloring
Time limit : 2sec / Memory limit : 1024MB
Score : 700 points
Problem Statement
Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the beauty of the tower as follows:
- The beauty of the tower is the sum of the scores of the N layers, where the score of a layer is A if the layer is painted red, A+B if the layer is painted green, B if the layer is painted blue, and 0 if the layer is uncolored.
Here, A and B are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors.
Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly K. How many such ways are there to paint the tower? Find the count modulo 998244353. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.
Constraints
- 1≤N≤3×105
- 1≤A,B≤3×105
- 0≤K≤18×1010
- All values in the input are integers.
Input
Input is given from Standard Input in the following format:
N A B K
Output
Print the number of the ways to paint tiles, modulo 998244353.
Sample Input 1
4 1 2 5
Sample Output 1
40
In this case, a red layer worth 1 points, a green layer worth 3 points and the blue layer worth 2 points. The beauty of the tower is 5 when we have one of the following sets of painted layers:
- 1 green, 1 blue
- 1 red, 2 blues
- 2 reds, 1 green
- 3 reds, 1 blue
The total number of the ways to produce them is 40.
Sample Input 2
2 5 6 0
Sample Output 2
1
The beauty of the tower is 0 only when all the layers are uncolored. Thus, the answer is 1.
Sample Input 3
90081 33447 90629 6391049189
Sample Output 3
577742975 pkusc之后非常难过qwq,刷道水题安慰自己qwq。
(这可能是组合计数模板题??)
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<ctime>
#define ll long long
using namespace std;
const int maxn=300005,ha=998244353;
inline void add(int &x,int y){ x+=y; if(x>=ha) x-=ha;}
inline int ksm(int x,int y){
int an=1;
for(;y;y>>=1,x=x*(ll)x%ha) if(y&1) an=an*(ll)x%ha;
return an;
} int jc[maxn],ni[maxn];
int N,A,B,ans;
ll K; inline int C(int x,int y){ return jc[x]*(ll)ni[y]%ha*(ll)ni[x-y]%ha;} inline void init(){
jc[0]=1;
for(int i=1;i<=N;i++) jc[i]=jc[i-1]*(ll)i%ha;
ni[N]=ksm(jc[N],ha-2);
for(int i=N;i;i--) ni[i-1]=ni[i]*(ll)i%ha;
} inline void solve(){
const int b=B,T=min((ll)N,K/A); for(int i=0;i<=T;i++){
if((K-A*(ll)i)%b) continue;
ll lef=(K-A*(ll)i)/b;
if(lef>N) continue; add(ans,C(N,i)*(ll)C(N,lef)%ha);
}
} int main(){
scanf("%d%d%d%lld",&N,&A,&B,&K); init(),solve(); printf("%d\n",ans);
return 0;
}
AGC 025 B - 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 ...
- [AGC025B]RGB Coloring
[AGC025B]RGB Coloring 题目大意: 有\(n(n\le3\times10^5)\)个格子,每个格子可以选择涂成红色.蓝色.绿色或不涂色,三种颜色分别产生\(a,b,a+b(a,b\ ...
- AGC 026 C - String Coloring
题面在这里! 比较简单的折半搜索,推一下hash函数,要求正反最后相等就行了. #include<bits/stdc++.h> #define ll unsigned long long ...
- AGC 26 D Histogram Coloring
题目 将柱子的高度离散化$\DeclareMathOperator{\dp}{dp}$ 设第 $i$ 根柱子实际高度是 $h_i$,离散化之后的高度是 $g_i$:第 $i$ 高的高度是 $H_i$, ...
- Solution -「AGC 026D」Histogram Coloring
\(\mathcal{Description}\) Link. 有 \(n\) 列下底对齐的方格纸排成一行,第 \(i\) 列有 \(h_i\) 个方格.将每个方格染成黑色或白色,求使得任意完 ...
- 【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 考虑可以进行的操作只有两种,即左拉和右拉,连续进行两次相同的操作是没有用的. 左拉时肯定会选 ...
- 【OpenGL】Shader实例分析(六)- 卡牌特效
转发请保持地址:http://blog.csdn.net/stalendp/article/details/30989295 本文将介绍怎么通过alpha通道来隐藏信息.并实现卡牌特效. 执行效果例如 ...
- RGB,CMYK,HSB各种颜色表示的转换 C#语言
Introduction Why an article on "colors"? It's the same question I asked myself before writ ...
随机推荐
- 【BZOJ 1930】 [Shoi2003]pacman 吃豆豆 最大费用最大流
如果你知道他是网络流的话你就很快会想到一个最大费用最大流的模型,然后你发现可能T,然而你发现你只用增广两次,然后你就开心的打了出来,然后发现被稠密图里spfa的丧病时间复杂度坑了,还是会T.于是我就开 ...
- 【BZOJ3887】【Usaco2015 Jan】Grass Cownoisseur Tarjan+Spfa
我们可以看出这个东西可以缩点成DAG,因为我们在所称的点里用特技的话,要么没用,要么削弱自己对点的收割能力与边的联通权,所以我们缩完点之后在图上枚举反向的变,因为我们只可能反向一条边,而且我们知道在这 ...
- 适用于iview的表格转Excel插件
在网上找的一个表格转excel插件,经过修改后使其适用于iview中的table组件 let idTmr; const getExplorer = () => { let explorer = ...
- oralce的客户端sqlplus
安装完oracle后,默认的客户端是sqlplus,还有一个公司常用的是PLSQLdeveloper 客户端软件,另外Navicat primie这个可以连接mysql.sqlserver.oracl ...
- 使用Word2010发布博客文章
发布博客可以直接在web页面上面编辑,也可以使用客户端编辑,其中客户端支持windows live writer以及word本身的发布博客功能.个人试用后倾向于使用word发布博客文章. 下面的内容转 ...
- 调整文本输入框placeholder的颜色等样式
input::-webkit-input-placeholder{ color: white !important;}input:-moz-placeholder{ color: whi ...
- Python基础(8)迭代器、生成器
一 什么是迭代 1 重复 2 下一次重复是基于上一次的结果 # while True: # cmd=input('>>: ') # print(cmd) # l=['a','b','c', ...
- EL遍历集合
jstl EL表达式遍历集合 博客分类: JSTL/EL JSTLEL遍历集合 在EL中,方括号运算符用来检索数组和集合的元素.对于实现 java.util.Map 接口的集合,方括号运算符使用关联 ...
- bzoj 5028: 小Z的加油店——带修改的区间gcd
Description 小Z经营一家加油店.小Z加油的方式非常奇怪.他有一排瓶子,每个瓶子有一个容量vi.每次别人来加油,他会让 别人选连续一段的瓶子.他可以用这些瓶子装汽油,但他只有三种操作: 1. ...
- 2017年上海金马五校程序设计竞赛:Problem K : Treasure Map (蛇形填数)
Description There is a robot, its task is to bury treasures in order on a N × M grids map, and each ...