NOIP11.14 score DP

来源:互联网 发布:服装数据分析文字 编辑:程序博客网 时间:2024/06/15 01:26

傻逼dp,然而我没有对拍,所以挂了。。结果发现是没有取dp的max值。。真的是惨痛的教训。。
代码:

var        t,k,p,n,m,j1:int64;        i,j:longint;        fuck:boolean;        ans:int64;        f:Array[0..200000]of int64;        a,b,c:array[0..200000]of int64;        d:Array[0..200000]of real;function max(x,y:int64):int64;begin        if x>y then exit(x)        else exit(y);end;procedure swap(var x,y:int64);var        t:int64;begin        t:=x;        x:=y;        y:=t;end;procedure qsort(l,r:int64);var        i,j:int64;        m,t:real;begin        i:=l;        j:=r;        m:=d[(l+r)div 2];        repeat                while d[i]>m do inc(i);                while d[j]<m do dec(j);                if i<=j then                begin                        swap(a[i],a[j]);                        swap(b[i],b[j]);                        swap(c[i],c[j]);                        t:=d[i];                        d[i]:=d[j];                        d[j]:=t;                        inc(i);                        dec(j);                end;        until i>j;        if l<j then qsort(l,j);        if i<r then qsort(i,r);end;begin        assign(input,'score.in');        assign(output,'score.out');        reset(input);        rewrite(output);        readln(t);        while t<>0 do        begin                read(n,m);                for i:=1 to n do                begin                        readln(a[i],b[i],c[i]);                        d[i]:=b[i]/c[i];                end;                qsort(1,n);                fillchar(f,sizeof(f),0);                k:=0;                for i:=1 to n do                begin                        for j:=m downto c[i] do                        begin                                k:=a[i]-b[i]*j;                                f[j]:=max(f[j],f[j-c[i]]+k);                        end;                end;                for i:=1 to m-1 do f[m]:=max(f[m],f[i]);                writeln(f[m]);                dec(t);        end;        close(input);        close(output);end.
0 0
原创粉丝点击