二维0-1背包,跟0-1背包没啥区别,数组多开一维就行
#include <bits/stdc++.h>
#define numm ch - 48
#define pd putchar(' ')
#define pn putchar('\n')
#define pb push_back
#define fi first
#define se second
#define fre1 freopen("1.txt", "r", stdin)
#define fre2 freopen("2.txt", "w", stdout)
typedef long long int ll;
typedef long long int LL;
using namespace std;
template<typename T>
void read(T &res) {
bool flag = false;
char ch;
while (!isdigit(ch = getchar())) (ch == '-') && (flag = true);
for (res = numm; isdigit(ch = getchar()); res = (res << 1) + (res << 3) + numm);
flag && (res = -res);
}
template<typename T>
void write(T x) {
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
//static auto _ = []() {
// ios::sync_with_stdio(false);
// cin.tie(0);
// return 0;
//}();
//#pragma GCC optimize(3, "Ofast", "inline")
//
int n, m, t;
int w[105][2];
int dp[205][205];
int main() {
read(n), read(m), read(t);
for (int i = 1; i <= n; i++) {
read(w[i][0]), read(w[i][1]);
}
int maxx = 0;
for (int i = 1; i <= n; i++) {
for (int j = m; j >= 0; j--) {
for (int k = t; k >= 0; k--) {
if ((j + w[i][0] <= m) && (k + w[i][1] <= t)) {
dp[j + w[i][0]][k + w[i][1]] = max(dp[j + w[i][0]][k + w[i][1]], dp[j][k] + 1);
maxx = max(maxx, dp[j + w[i][0]][k + w[i][1]]);
}
}
}
}
write(maxx);
return 0;
}