uva12563 Jin Ge jin Qu hao

Source: Internet
Author: User

Title Description:

Choose a certain number of songs from the N song, each song needs a certain time to sing:

1, the requirement is not more than the time st-1 conditions, the number of selected the most;

2, the second in the same number of cases, the song time required to maximize the total.


Problem Solving Ideas:

Essence 0, 1 knapsack problem, the time of each song as the volume of goods, value assigned to 1, backpack capacity of st-1

How to solve the greatest number of songs on the basis of the total time sum?

Record updates in the process of moving the rules:

1. The current state is more than the number that has been asked, the maximum number of updates and the longest elapsed time

2, the current state and the number of the request, the maximum time to update


#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;int d[10010];int time [60 ];int N,st;int Main () {    int T;    scanf ("%d", &t);    for (int t=1; t<=t; ++t)    {        scanf ("%d%d", &n,&st);        for (int i=1; i<=n; ++i)            scanf ("%d", &time[i]);        int ans=0;        int maxx=0;        Memset (d,0,sizeof (d));        for (int i=n; i>=1;-I.) for            (int j=st-1; j>=time[i];--j)            {                if (j==time[i]| | D[J-TIME[I]]>0)//whether to add the current item                {                    D[j]=max (d[j],d[j-time[i]]+1);                    if (d[j]>maxx| | (D[j]==maxx&&j>ans)) Maximum volume, maximum value status update                    {                        ans=j;                        MAXX=D[J];}}            }        printf ("Case%d:%d%d\n", t,maxx+1,ans+678);    }    return 0;}

Harvest:

Record certain states and update them during dynamic planning

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

uva12563 Jin Ge jin Qu hao

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.