2011noip day1 选择客栈
今天在别人的帮助下完成了这个程序,
首先我用O(kn)的算法,但有2个点超了
后来用了O(N)的算法过了。
program wu; 02 var 03 c,m,s,f,a:array[0..200001]of longint; 04 ou:array[0..50,0..200001]of longint; 05 oy:array[0..50] of longint; 06 o,n,k,p,i,j,l,ans,maxa,maxb,tot:longint; 07 begin 08 ans:=0; 09 readln(n,k,p); 10 for i:=1 to n do 11 readln(c[i],m[i]); 12 for i:=1 to n do begin 13 inc(oy[c[i]]); 14 ou[c[i],oy[c[i]]]:=i; 15 if m[i]<=p then f[i]:=f[i-1]+1 16 else f[i]:=f[i-1]; 17 end; 18 for j:=0 to k-1 do 19 begin 20 tot:=0; 21 maxa:=0; 22 maxb:=0; 23 for o:=1 to oy[j] do begin 24 i:=ou[j,o]; 25 if tot<>0 then begin 26 if f[i]-f[tot-1]>0 then begin maxa:=maxa+maxb;maxb:=1;end 27 else inc(maxb); 28 tot:=i; 29 end 30 else 31 begin 32 maxb:=1; 33 tot:=i; 34 end; 35 ans:=ans+maxa; 36 end; 37 end; 38 writeln(ans); 39 end.
其实就是一个递推,但我还需加强练习。
浙公网安备 33010602011771号