Hangzhou Electric 4508 Series story--weight loss kee i "full backpack"

Source: Internet
Author: User

Problem-solving ideas: Because food can be casually eaten, so is a complete backpack, calorie represents consumption, happiness represents value, set of formula can be done.

Problem Description for foodies, the happiest thing about the new Year is to eat, not one!   But for girls, calories are predators. Senior beauty is familiar with the "fat to fall like a mountain, fat to go like a ladder," the truth, so she hoped you can help develop a recipe, can make her eat happy at the same time, will not make too many predators.
Of course, to make your recipes easier, the waterfall gives you a list of daily foods that describe the level of happiness that every food she wants to eat and the amount of calories it will increase.   Input inputs contain multiple sets of test cases. Each set of data begins with an integer n, which indicates that the daily food list has n foods.
Next n lines, two integers a and b per line, where a indicates that the food can give the happiness value of the waterfall (the greater the value, the happier it is), and B is the amount of calories that the food will absorb in a waterfall. The last is an integer m, which means that the calories absorbed by the waterfall can not exceed m per day.
   [Technical specification]1.1 <= n <= 100 2. 0 <= A, b <= 100000 3. 1 <= m <= 100000 output for each list, outputs an integer, which is the maximum happiness that can be achieved while the calorie uptake is met. Sample Input33 PNs 91051 310-Output1020
#include <stdio.h> #include <string.h>int f[100010],a[100010],b[100010];int max (int a,int b) {    if (a >B)    return A;    else    return b;} int main () {    int n,i,v,m;    while (scanf ("%d", &n)!=eof)    {        memset (f,0,sizeof (f));        for (i=1;i<=n;i++)        scanf ("%d%d", &a[i],&b[i]);        scanf ("%d", &m);        for (i=1;i<=n;i++)        {for            (v=b[i];v<=m;v++)            F[v]=max (F[v],f[v-b[i]]+a[i]);        }        printf ("%d\n", F[m]);}    }

  

Hangzhou Electric 4508 Series story--weight loss kee i "full backpack"

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.