[DP review] 01 backpack renew

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.