Solution
这题其实很好想到用 DP。设 表示选 个数和为 的情况。由于题目中到只能放入值 的数,那么 、 一定满足 。
现在考虑如何转移。
- 边界: ;
- 若放入 ,则显然 ;
- 若放入的是分数,由于分数都等于 ,那么可以考虑将原序列所有元素乘 ,再加入一个元素使得该序列和为 ,此时 。
注意 要从大到小操作,因为要先求出 。
Code
#include<bits/stdc++.h>
using namespace std;
int N, K;
int DP[5005][5005];
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cin >> N >> K, DP[0][0] = 1;
for (register int i = 1; i <= N; ++i) for (register int j = i; j >= 1; j--) {
DP[i][j] = DP[i - 1][j - 1];
if ((j << 1) <= i) DP[i][j] = (DP[i][j] + DP[i][j << 1] > 998244353 ? DP[i][j] + DP[i][j << 1] - 998244353 : DP[i][j] + DP[i][j << 1]);
}
cout << DP[N][K] << endl;
return 0;
}