【计数】tower


看了题解完全觉得是sb题。。。那么 = =作为一个sb题都做不来的。。。

设dp[i] 为前i 个的方案数,那么枚举所有能在上面放i 的积木j,就会对答案带来dp[i - 1]的贡献。


#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

int read()
{
	int n = 0, sign = 1; char c = getchar();
	while(c < '0' || c > '9') {if(c == '-') sign = -1; c = getchar(); }
	while(c >= '0' && c <= '9') { n = n*10 + c-'0'; c = getchar(); }
	return n * sign;
}

const int Mod = 998244353;

int N, D;
int a[700005];
int ans;

int main()
{
	freopen("tower.in", "r", stdin);
	freopen("tower.out", "w", stdout);
	
	N = read(), D = read();
	for (int i = 1; i <= N; ++i) a[i] = read();
	sort(a + 1, a + N + 1); ans = 1;
	
	for (int i = 2, j = 1; i <= N; ++i) {
		while (a[j] + D < a[i]) ++j;
		ans = 1ll * ans * (i - j + 1) % Mod;
	}
	
	printf("%d\n", ans);
	
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值