You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
663 B

#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
const int MOD = 1e9 + 7;
int f[N], g[N];
int main() {
int n, m;
scanf("%d%d", &n, &m);
f[0] = 0, g[0] = 1;
for (int i = 1; i <= m; i++) f[i] = 0, g[i] = 1;
for (int i = 1; i <= n; i++) {
int v, w;
scanf("%d%d", &v, &w);
for (int j = m; j >= v; j--) {
int val = f[j - v] + w;
if (val > f[j]) {
f[j] = val;
g[j] = g[j - v];
} else if (val == f[j])
g[j] = (g[j] + g[j - v]) % MOD;
}
}
printf("%d", g[m]);
return 0;
}