9 degree tutorial 101st questions

Source: Internet
Author: User

Provide group data: input: 105 1012 1116 1624 157 929 2432 255 343 3231 411 7 output: 112C source code: [cpp] # include <stdio. h> int dp [101] [1001]; typedef struct grass {int time; int worth;} grass; grass g [101]; int max (int a, int B) {return a> B? A: B;} int main () {int t, n, I, j; while (scanf ("% d", & t, & n )! = EOF) {for (I = 1; I <= n; I ++) scanf ("% d", & g [I]. time, & g [I]. worth); for (I = 0; I <= n; I ++) for (j = 0; j <= t; j ++) dp [I] [j] = 0; for (I = 1; I <= n; I ++) {for (j = 0; j <= t; j ++) {if (g [I]. time <= j) dp [I] [j] = max (dp [I-1] [j-g [I]. time] + g [I]. worth, dp [I-1] [j]); else dp [I] [j] = dp [I-1] [j];} printf ("% d \ n ", dp [n] [t]) ;}}

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.