11.背包问题求方案数
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int dp[N], cnt[N], v, w, s;
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i <= m; i++) cnt[i] = 1;
for (int i = 1; i <= n; i++) {
cin >> v >> w;
for (int j = m; j >= v; j--) {
int s = dp[j - v] + w;
if (s == dp[j]) cnt[j] = (cnt[j] + cnt[j - v]) % 1000000007;
if (s > dp[j]) dp[j] = s, cnt[j] = cnt[j - v];
}
}
cout << cnt[m];
return 0;
}