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 ...
随机推荐
- pb_ds
#include<ext/pb_ds/priority_queue.hpp>#define ll long long#define pa pair<ll,int>using n ...
- Codeforces Round #515 (Div. 3) E. Binary Numbers AND Sum
E. Binary Numbers AND Sum 题目链接:https://codeforces.com/contest/1066/problem/E 题意: 给出两个用二进制表示的数,然后将第二个 ...
- Codeforces Round #478 C. Valhalla Siege
C. Valhalla Siege time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- peity(jQuery 插件可以将元素内容转换为一个小的 <svg> 饼图,圆环图,条形图和折线图)
API地址:https://www.awesomes.cn/repo/benpickles/peity 实例效果
- Hibernate 懒加载 错误----no session
错误: unable to evaluate the expression Method threw 'org.hibernate.LazyInitializa org.hibernate.LazyI ...
- poj 1528 Perfection
题目链接:http://poj.org/problem?id=1528 题目大意:输入一个数n,然后求出约数的和sum,在与这一个数n进行比较,如果sum>n,则输出ABUNDANT,如果sum ...
- <script>中的async与defer属性
1.script元素中的defer属性 1.1说明 使用该属性可以使脚本延迟到文档完全被解析和显示之后再按照原本的顺序执行,即告诉浏览器立即下载脚本,但延迟执行,该属性只对外部脚本有效 1.2使用方法 ...
- Educational Codeforces Round 40 A B C D E G
A. Diagonal Walking 题意 将一个序列中所有的\('RU'\)或者\('UR'\)替换成\('D'\),问最终得到的序列最短长度为多少. 思路 贪心 Code #include &l ...
- [Leetcode Week6]Linked List Cycle
Linked List Cycle 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/linked-list-cycle/description/ Des ...
- C# 文件选择对话框
方法一:系统自带 <asp:FileUpload ID="FileSelect" runat="server" /> 方法二:ShowDialog( ...