题解

303 条题解

  • 0
    @ 2008-11-09 21:23:11

    #include

    using namespace std;

    int work(int n,int m,int a[],int b[],int k)

    {int maxx=0,i;

    if(k) for(i=1;in;i--)

    if(a[i]b[maxx])

    maxx=i;

    return b[maxx];

    }

    int main()

    {int a[100001],b[100001],c[100001],k,maxx,i;

    cin>>k;

    b[0]=0;

    c[0]=0;

    for(i=1;i>a[i];

    b[i]=0;

    c[i]=0;

    }

    maxx=0;

    for(i=1;i0;i--)

    {c[i]=work(i,k,a,c,0)+1;

    if(c[i]+b[i]>=maxx) maxx=c[i]+b[i];

    }

    cout

  • 0
    @ 2008-11-07 20:45:33

    一个不等号方向打错提交4次- -

  • 0
    @ 2008-11-07 20:32:43

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    当 x x/y

    由上述结论知,通过率提升中

  • 0
    @ 2008-11-07 09:11:12

    BTMHLY

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    楼上的程序太冗长。。

    program Ltr;

    var a,a1,a2:array[1..100] of integer;

    i,j,max,min,tmp,n:integer;

    begin

    readln(n);for i:=1 to n do read(a[i]);min:=101;

    for i:=1 to n do begin

    j:=i-1;max:=0;

    while j>=1 do begin

    if (a[j]max)then ax:=a1[j];dec(j);

    end;

    a1[i]:=max+1;

    end;

    for i:=n downto 1 do begin

    j:=i+1;max:=0;

    while j

  • 0
    @ 2008-11-05 20:18:31

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    两次求最长不下降子序列

    program hly;

    const cmax=100;

    var

    a1,a2,b,c:array[1..cmax] of longint;

    n,ans:longint;

    procedure init;

    var

    i:longint;

    begin

    readln(n);

    for i:=1 to n do

    begin

    read(a1[i]);

    a2[n-i+1]:=a1[i];

    b[i]:=1;c[i]:=1;

    end;

    end;

    procedure work;

    var

    i,j,max:longint;

    begin

    for i:=2 to n do

    begin

    max:=0;

    for j:=1 to i-1 do

    if (a1[j]max) then

    max:=b[j];

    b[i]:=b[i]+max;

    end;

    for i:=2 to n do

    begin

    max:=0;

    for j:=1 to i-1 do

    if (a2[j]max) then

    max:=c[j];

    c[i]:=c[i]+max;

    end;

    max:=0;

    for i:=1 to n do

    if b[i]+c[n-i+1]>max then max:=b[i]+c[n-i+1];

    ans:=n-max+1;

    writeln(ans);

    end;

    begin

    init;

    work;

    end.

  • 0
    @ 2008-11-05 17:13:43

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    #include

    using namespace std;

    int s (int n,int a[],int b[],int k,int s)

    {

    int max=0;

    if (k)

    {

    for (int i=1;in;i--)

    if (a[i]b[max])

    max=i;

    }

    return b[max];

    }

    main ()

    {

    int n;

    cin>>n;

    int a[n+1],b[n+1],c[n+1];

    b[0]=c[0]=0;

    for (int i=1;i>a[i];

    b[i]=c[i]=0;

    }

    int max=0;

    for (int i=1;i=1;i--)

    {

    c[i]=s(i,a,c,0,n)+1;

    if (c[i]+b[i]>=max)

    max=c[i]+b[i];

    }

    cout

  • 0
    @ 2008-11-05 12:47:37

    var

    a,b,c:array[1..101] of longint;

    n,i,j,max:longint;

    begin

    readln(n);

    for i:=1 to n do read(a[i]);

    for i:=1 to n do begin b[i]:=1;c[i]:=1;end;

    for i:=2 to n do

    begin max:=0;

    for j:=1 to i-1 do

    if (a[j]max) then max:=b[j];

    b[i]:=b[i]+max;

    end;

    for i:=n-1 downto 1 do

    begin max:=0;

    for j:=i+1 to n do

    if (a[j]max) then max:=c[j];

    c[i]:=c[i]+max;

    end;

    max:=0;

    for i:=1 to n do

    if b[i]+c[i]>max then max:=b[i]+c[i];

    write(n-max+1);

    end.

  • 0
    @ 2008-11-03 13:09:15

    var opt1,opt2,a:array[0..200] of longint;

    n,ans,i,j:longint;

    begin

    readln(n);

    for i:=1 to n do read(a[i]);

    a[0]:=-maxlongint;

    for i:=1 to n do

    for j:=i-1 downto 0 do

    if (a[j]opt1[i])

    then opt1[i]:=opt1[j]+1;

    a[n+1]:=-maxlongint;

    for i:=n downto 1 do

    for j:=i+1 to n+1 do

    if (a[j]opt2[i])

    then opt2[i]:=opt2[j]+1;

    ans:=0;

    for i:=1 to n do

    if opt1[i]+opt2[i]>ans

    then ans:=opt1[i]+opt2[i];

    writeln(n-ans+1);

    end.

  • 0
    @ 2008-11-02 07:50:09

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    program hechang;

    var n:2..100;

    t:array[1..100] of 130..230;

    s,x,f:array[1..100] of byte;

    i,j,k,m1,m2,max:integer;

    begin

    readln(n);

    for i:=1 to n do read(t[i]);

    s[1]:=1; x[n]:=1;

    for i:=2 to n do begin

    m1:=0;s[i]:=1;

    for j:=1 to i-1 do

    if t[j]m1 then m1:=s[j];

    s[i]:=m1+1;

    end;

    for i:=n-1 downto 1 do begin

    m2:=0;x[i]:=1;

    for j:=n downto i+1 do

    if t[j]m2 then m2:=x[j];

    x[i]:=m2+1;

    end;max:=0;

    for i:=1 to n-1 do

    for j:=i to n do

    if j=i then begin if s[i]+x[j]-1>max then max:=s[i]+x[j]-1; end

    else if t[i]t[j] then

    if s[i]+x[j]>max then max:=s[i]+x[j];

    writeln(n-max);

    end.

    学会了动态的第四题!

    晕死,最长下降序列打错,交了几次才AC!~

  • 0
    @ 2008-10-28 22:30:16

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    好水啊

  • 0
    @ 2008-10-27 17:19:32

    那个n^2的状态方程是什么来着?

    只记得nlogn...脑残中

    求最长上升:

    readln(n);

    for i:=1 to n do read(a[i]);

    len:=0;

    for i:=1 to n do

    begin

    f[len+1]:=maxlongint;

    l:=1;r:=len+1;

    while r-l>1 do

    begin

    x:=(l+r)div 2;

    if f[x]>a[i] then r:=x-1 else l:=x+1;

    end;

    while not ((f[l-1]=a[i])) do inc(l);

    f[l]:=a[i];

    if l>len then inc(len);

    end;

  • 0
    @ 2008-10-26 23:11:05

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

  • 0
    @ 2008-10-20 12:25:38

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

  • 0
    @ 2008-10-16 11:34:25

    最长上升子序列,从两边求,枚举中间最高的人。

  • 0
    @ 2008-10-12 19:43:38

    李玉东的思路可真是一团乱麻……看都看不懂

  • 0
    @ 2008-10-11 15:03:50

    var f,g:array[1..100] of integer;

    a:array[1..100] of integer;

    n,i,j,max:integer;

    begin

    readln(n);

    for i:=1 to n do read(a[i]);

    f[1]:=1; g[1]:=1;

    for i:=2 to n do

    begin

    for j:=1 to i-1 do

    if (a[j]f[i]) then f[i]:=f[j];

    f[i]:=f[i]+1;

    for j:=1 to i-1 do

    if (a[j]>a[i]) and (g[j]>g[i]) then g[i]:=g[j];

    g[i]:=g[i]+1;

    end;

    max:=1;

    for i:=1 to n do

    if (f[i]+g[i]-1>max) then max:=f[i]+g[i]-1;

    writeln(n-max);

    end.

    谁能告诉我这道题错在哪儿啦?

  • 0
    @ 2008-10-11 13:53:32

    var

    n,i,j,k,l:integer;

    a,b:array[1..1000,1..3]of integer;

    begin

    readln(n);

    for i:=1 to n do

    begin read(a);b[n-i+1,1]:=a;a:=1;b[n-i+1,2]:=1;end;

    for i:=n-1 downto 1 do

    begin

    l:=0;k:=0;

    for j:=i+1 to n do

    begin

    if (a>a[j,1])and(a[j,2]>l)then l:=a[j,2];

    if (b>b[j,1])and(b[j,2]>k)then k:=b[j,2];

    end;

    if l>0 then a:=l+1;if k>0 then b:=k+1;

    end;

    k:=0;

    for i:=1 to n do begin a:=a+b[n-i+1,2]-1;

    if a>k then k:=a; end;

    writeln(n-k); 燕麦

    end.

  • 0
    @ 2008-10-11 13:45:22

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

  • 0
    @ 2008-10-06 23:27:15

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    最朴素的动归 N^2的算法

  • 0
    @ 2008-10-06 18:53:40

    最长公共子序列 晕 好水 AC了

信息

ID
1098
难度
5
分类
动态规划 | LIS 点击显示
标签
递交数
12819
已通过
4882
通过率
38%
被复制
20
上传者