首先对于这个题目背景,,个人认为很(you)好(qu),,,
核心就是一个裸的二维费用背包,刚刚学习的同学参见dd大牛的背包九讲
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 5 6 int n, m, t; 7 int dp[210][210]; 8 int mi, ti; 9 10 11 int main () { 12 scanf("%d %d %d", &n, &m, &t); 13 for (int i = 1; i <= n; i++) { 14 scanf("%d %d", &mi, &ti); 15 for (int j = m; j >= mi; j--) 16 for (int k = t; k >= ti; k--) { 17 dp[j][k] = std :: max(dp[j][k], dp[j-mi][k-ti] + 1); 18 } 19 } 20 printf("%d", dp[m][t]); 21 return 0; 22 }