QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#784796#9798. Safety Firstucup-team052ML 0ms0kbC++231.3kb2024-11-26 15:58:132024-11-26 15:58:24

Judging History

你现在查看的是最新测评结果

  • [2024-11-26 15:58:24]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [2024-11-26 15:58:13]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int md = 998244353;

inline int add(int x, int y) {
	if (x + y >= md) return x + y - md;
	return x + y;
}

inline int sub(int x, int y) {
	if (x < y) return x - y + md;
	return x - y;
}

inline int mul(int x, int y) {
	return 1ull * x * y % md;
}

int fpow(int x, int y) {
	int ans = 1;
	while (y) {
		if (y & 1) ans = mul(ans, x);
		y >>= 1; x = mul(x, x);
	}
	return ans;
}

const int N = 2005, B = 45;

int dp[N][N][B], f[N][N];
int T, n, m;

int main() {
	dp[1][B][1] = 1;
	for (int i = 0; i <= 2000; i++) {
		for (int j = 0; j <= 2000; j++) {
			for (int k = 1; k <= min(i, 44); k++) {
				int tmp = dp[i][j][k];
				if (!tmp) continue;
				dp[i + 1][j][k] = add(dp[i + 1][j][k], tmp);
				if (j + k <= 2000) dp[i][j + k][k] = add(dp[i][j + k][k], tmp);
				if (j + B <= 2000) dp[i + 1][j + B][k + 1] = add(dp[i + 1][j + B][k + 1], tmp);
				f[i][j] = add(f[i][j], tmp);
			}
		}
	}
	
	for (int t = B - 1; t >= 1; t--) {
		f[1][t] = add(f[1][t], 1);
		for (int i = 0; i <= 2000; i++) {
			for (int j = 0; j <= 2000; j++) {
				f[i + 1][j] = add(f[i + 1][j], f[i][j]);
				if (j + t <= 2000) f[i + 1][j + t] = add(f[i + 1][j + t], f[i][j]);
			}
		}
	}
	scanf("%d", &T);
	while (T--) {
		scanf("%d%d", &n, &m);
		printf("%d\n", f[n][m]);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Memory Limit Exceeded

input:

3
1 3
2 3
3 3

output:

1
4
10

result: