榨取kkksc03 luogu1855 dp 裸二维费用背包
首先对于这个题目背景,,个人认为很(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 }
![zb](https://images.cnblogs.com/cnblogs_com/CtsNevermore/901911/o_%E7%A5%88%E7%A5%B7%E5%96%B5_%E7%98%A6_%E5%89%AF%E6%9C%AC.jpg)