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

Copy
4 1 2 5

Sample Output 1

Copy
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

Copy
2 5 6 0

Sample Output 2

Copy
1

The beauty of the tower is 0 only when all the layers are uncolored. Thus, the answer is 1.


Sample Input 3

Copy
90081 33447 90629 6391049189

Sample Output 3

Copy
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的更多相关文章

  1. 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 ...

  2. [AGC025B]RGB Coloring

    [AGC025B]RGB Coloring 题目大意: 有\(n(n\le3\times10^5)\)个格子,每个格子可以选择涂成红色.蓝色.绿色或不涂色,三种颜色分别产生\(a,b,a+b(a,b\ ...

  3. AGC 026 C - String Coloring

    题面在这里! 比较简单的折半搜索,推一下hash函数,要求正反最后相等就行了. #include<bits/stdc++.h> #define ll unsigned long long ...

  4. AGC 26 D Histogram Coloring

    题目 将柱子的高度离散化$\DeclareMathOperator{\dp}{dp}$ 设第 $i$ 根柱子实际高度是 $h_i$,离散化之后的高度是 $g_i$:第 $i$ 高的高度是 $H_i$, ...

  5. Solution -「AGC 026D」Histogram Coloring

    \(\mathcal{Description}\)   Link.   有 \(n\) 列下底对齐的方格纸排成一行,第 \(i\) 列有 \(h_i\) 个方格.将每个方格染成黑色或白色,求使得任意完 ...

  6. 【AtCoder】AGC025题解

    A - Digits Sum 枚举即可 代码 #include <bits/stdc++.h> #define fi first #define se second #define pii ...

  7. AGC025简要题解

    AGC025简要题解 B RGB Coloring 一道简单题,枚举即可. C Interval Game 考虑可以进行的操作只有两种,即左拉和右拉,连续进行两次相同的操作是没有用的. 左拉时肯定会选 ...

  8. 【OpenGL】Shader实例分析(六)- 卡牌特效

    转发请保持地址:http://blog.csdn.net/stalendp/article/details/30989295 本文将介绍怎么通过alpha通道来隐藏信息.并实现卡牌特效. 执行效果例如 ...

  9. RGB,CMYK,HSB各种颜色表示的转换 C#语言

    Introduction Why an article on "colors"? It's the same question I asked myself before writ ...

随机推荐

  1. 【NOIP模拟赛】藏宝图 最小生成树

    性质:我们把最小生成树建出来,如果其距离符合那么就是对的,不符合就是错的 因为这是个n^2的图所以不能Kruskal只能Prim #include <cstdio> #include &l ...

  2. 禁止 iphone 网页上下拖动露底

    document.addEventListener('touchmove', function(e) { e.preventDefault();});

  3. Spring源码解析-基于注解依赖注入

    在spring2.5版本提供了注解的依赖注入功能,可以减少对xml配置. 主要使用的是 AnnotationConfigApplicationContext: 一个注解配置上下文 AutowiredA ...

  4. swagger学习2

    转:http://blog.csdn.net/fansunion/article/details/51923720 写的非常好,非常详细,推荐!!!! 最常用的5个注解 @Api:修饰整个类,描述Co ...

  5. HBase并行写机制(mvcc)

    HBase在保证高性能的同时,为用户提供了便于理解的一致性数据模型MVCC (Multiversion Concurrency Control),即多版本并发控制技术,把数据库的行锁与行的多个版本结合 ...

  6. 理解JWT(JSON Web Token)认证及python实践

    原文:https://segmentfault.com/a/1190000010312468?utm_source=tag-newest 几种常用的认证机制 HTTP Basic Auth HTTP ...

  7. 如何实现用户id生成一个唯一邀请码

    #如何实现用户id生成一个唯一邀请码 #创建验证码 function createCode($user_id) { static $source_string = 'E5FCDG3HQA4B1NOPI ...

  8. WebSocket最简易理解,term.js插件的使用

    介绍WebSocket WebSocket我想大家并不陌生,无论你的的工作中是否用到了它,都或多或少听说过,它是h5中新增的,在某些方面可以很好的替代我们一直沿用的ajax技术,甚至更加的出色.但是它 ...

  9. Linux curl命令【curl】

    命令:curl 在Linux中curl是一个利用URL规则在命令行下工作的文件传输工具,可以说是一款很强大的http命令行工具.它支持文件的上传和下载,是综合传输工具,但按传统,习惯称url为下载工具 ...

  10. python基础===两个list合并成一个dict的方法

    def Run(): list2 = [, , , , ]; list3 = ["a", "b", "c", "d",& ...