zoukankan      html  css  js  c++  java
  • bzoj1334

     1 var f:array[0..100005] of boolean;
     2     a:array[0..310] of longint;
     3     i,n,s,j,ans:longint;
     4 
     5 procedure sort(l,r: longint);
     6   var i,j,x,y: longint;
     7   begin
     8     i:=l;
     9     j:=r;
    10     x:=a[(l+r) div 2];
    11     repeat
    12       while (a[i]<x) do inc(i);
    13       while (x<a[j]) do dec(j);
    14       if not(i>j) then
    15       begin
    16         y:=a[i]; a[i]:=a[j]; a[j]:=y;
    17         inc(i);
    18         j:=j-1;
    19       end;
    20     until i>j;
    21     if l<j then sort(l,j);
    22     if i<r then sort(i,r);
    23   end;
    24 
    25 begin
    26   readln(n);
    27   for i:=1 to n do
    28   begin
    29     read(a[i]);
    30     s:=s+a[i];
    31   end;
    32   sort(1,n);
    33   f[0]:=true;
    34   for i:=n downto 1 do
    35     for j:=s-a[i] downto 0 do
    36       if f[j] then
    37       begin
    38         f[j+a[i]]:=true;
    39         if (j<=s div 2) and (j+a[i]>s div 2) then
    40           if ans<j+a[i] then ans:=j+a[i];
    41       end;
    42   writeln(ans);
    43 end.
    View Code
  • 相关阅读:
    Servlet和Filter的url匹配
    iterator的用法
    python学习笔记
    python的序列之列表
    java开发实战学习笔记3
    java学习笔记4
    Java Java集合
    Struts2中的几个符号
    DbHelper.cs
    做word,excel时需要引用com
  • 原文地址:https://www.cnblogs.com/phile/p/4473028.html
Copyright © 2011-2022 走看看