Const ref nbsp using str pac std backpack Review
The Qaq in which PJ-is cut in 10 s
P1048 medicine collection
1 #include<cstdio> 2 #include<iostream> 3 using namespace std; 4 const int sz = 1010; 5 int dp[sz], val[sz], tim[sz]; 6 int t, m; 7 int main() { 8 scanf("%d%d", &t, &m); 9 for(int i = 1; i <= m; i++) 10 scanf("%d%d", &tim[i], &val[i]);11 for(int i = 1; i <= m; i++) {12 for(int j = t; j >= 0; j--) {13 if(j >= tim[i])14 dp[j] = max(dp[j - tim[i]] + val[i], dp[j]);15 }16 }17 printf("%d", dp[t]);18 return 0;19 }
P1049 Packing Problem
1 #include<cstdio> 2 #include<iostream> 3 using namespace std; 4 const int sz = 20020; 5 int n, m, use[sz], dp[sz]; 6 int main() { 7 scanf("%d%d", &m, &n); 8 for(int i = 1; i <= n; i++) 9 scanf("%d", &use[i]);10 for(int i = 1; i <= n; i++) {11 for(int j = m; j >= 0; j--) {12 if(j >= use[i])13 dp[j] = max(dp[j - use[i]] + use[i], dp[j]);14 }15 }16 printf("%d",m - dp[m]);17 return 0;18 }
[DP review] 01 backpack renew