P2392 kkksc03 exam cramming 01- backpack P2663 more the more the team

P2392 kkksc03 exam cramming

answer

01 backpack, similar to this question, the similarity 99.999999%:

01- backpack P2663 more the more the team

 
A total of four families, each subject independent of time, then do it again P2663 each subject the more the more the team, and accumulation of time to get an answer
 
Consider the shortest time to review each department
And since the left and right brain, and therefore subject to all the questions put to simplify what is divided into two groups, a group of the longest access time as the answer, but to allow the longest set of its time as short as possible
We know that the closer the two sets of values, be sure it is the best answer
 

Code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>

using namespace std;

typedef long long ll;

inline int read()
{
    int ans=0;
    char last=' ',ch=getchar();
    while(ch<'0'||ch>'9') last=' ',ch=getchar();
    while(ch>='0'&&ch<='9') ans=ans*10+ch-'0',ch=getchar();
    if(last=='-') ans=-ans;
    years;return
}

int cnt [ 5 ], s [ 25 ];
int f [ 3000 ];
int years = 0 , tot = 0 , ave = 0 ;

int main ()
{
    for(int i=1;i<=4;i++) cnt[i]=read();
    for(int t=1;t<=4;t++){
        memset(s,0,sizeof(s));
        memset(f,0,sizeof(f));
        tot=0,ave=0;
        for(int i=1;i<=cnt[t];i++) s[i]=read(),tot+=s[i];
        ave=tot/2;
        for(int i=1;i<=cnt[t];i++)
            for(int j=ave;j>=s[i];j--)
                f[j]=max(f[j],f[j-s[i]]+s[i]);
        years + = (early- f [ave]);
    }
    printf("%d\n",ans);
    
    return 0;
}

 

 

Guess you like

Origin www.cnblogs.com/xiaoyezi-wink/p/11983927.html