17233 singing Contest
Time limit: 1000MS memory limit: 65535K
Number of submissions: 8 by Number: 6 Revenue: 37
Question types: programming language: g++; Gcc
Description
Alice likes singing very much. He is going to attend a singing contest. Alice sings n songs, and each song has a singing time and tone. Assume that the first song is sung at Dura[i] and the tone is tone[i]. Alice found it difficult to sing songs of different tones in succession. When he finishes singing the first song, he prepares to sing the first J song, he needs | TONE[I]-TONE[J] | Time to adjust. It is known that Alice has only time t to perform. Let's say that Alice will be able to sing any song at once, and every song he chose is arbitrary. Now Alice wants to know how many songs he can sing within a given time frame.
Input format
Multiple examples, EOF end. For each sample, the first behavior is n. (1<=n<=15) The second line has N integers dura[i], which represents the time of each song's singing. (dura[i]<=1000000) The third line has n integers tone[i], which represents the pitch of each song. (tone[i]<=1000000) The fourth line, an integer t, represents Alice's performance time.
Output format
Each sample outputs an integer that indicates how many songs Alice can sing in a given time frame.
Input sample
59 5 2 5 58 7 1 3 314
Output sample
3
Source
Farmer
Author
201131000903
Because the tone conversion is time-consuming, it needs to be ordered, and then DFS is good.
#include <iostream>#include<stdio.h>#include<cstdlib>#include<algorithm>#include<cmath>#include<cstring>#include<stack>#include<map>#include<Set>#include<string>#include<vector>#include<queue>#defineCL (a) memset (a, 0, sizeof (a))using namespaceStd;typedefLong LongLL;Const intMAXN = 1e5+5;Const intM = maxn* -;Const intMoD = 1e9+7;Const DoubleEPS = 1e-7;Const intINF =0x3f3f3f;ConstLL INF = 1ll<< -;Const intN = 1e5 +7;intN; LL T;intans;structNode {intDura; inttone; BOOL operator< (ConstNode&a)Const { if(tone!=a.tone) {returntone<A.tone; } Else returndura<A.dura; }} si[ -];voidinit () {ans=0; for(inti =0; I < n; i++) {scanf ("%d",&Si[i].dura); } for(inti =0; I < n; i++) {scanf ("%d",&Si[i].tone); } CIN>>u; Sort (Si,si+n);//for (int i = 0; i < n; i++) {//cout<<si[i].dura<< "" <<si[i].tone<<endl;// }}voidDfsintCurintRemain,intCntintLast ) {ans=Max (Cnt,ans); if(cur==n)return; intWaste= (last!=-1? ABS (Si[last].tone-si[cur].tone):0)+Si[cur].dura; if(remain>=waste) DFS (cur+1, remain-waste,cnt+1, cur); DFS (cur+1, remain,cnt,last);}voidsolve () {DFS (0T0,-1); printf ("%d\n", ans);}intMain () {#ifdef local freopen ("inch","R", stdin);#endif //Local while(cin>>N) {init (); Solve (); }}
View Code
Scauoj 17233 Singing Contest