题解

257 条题解

  • 0
    @ 2009-10-05 20:06:18

    范围是2000

    还有一个0在下一行 害我没看到 wa掉了 555555

  • 0
    @ 2009-09-20 02:58:49

    郁闷,这种水题还让我wa了2次

    开始时,动态规划数组里初始值设定为0(即没有处理过)结果:

    编译通过...

    ├ 测试数据 01:运行超时...

    ├ 测试数据 02:运行超时...

    ├ 测试数据 03:运行超时...

    ├ 测试数据 04:运行超时...

    ├ 测试数据 05:运行超时...

    ├ 测试数据 06:运行超时...

    ├ 测试数据 07:运行超时...

    ├ 测试数据 08:运行超时...

    ├ 测试数据 09:运行超时...

    ├ 测试数据 10:运行超时...

    之后,自以为做了一个很大的减支:结果:

    编译通过...

    ├ 测试数据 01:运行超时...

    ├ 测试数据 02:运行超时...

    ├ 测试数据 03:运行超时...

    ├ 测试数据 04:运行超时...

    ├ 测试数据 05:运行超时...

    ├ 测试数据 06:运行超时...

    ├ 测试数据 07:运行超时...

    ├ 测试数据 08:运行超时...

    ├ 测试数据 09:运行超时...

    ├ 测试数据 10:运行超时...

    在之后,尝试将动态规划数组里的初值设为-1

    结果:

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    贴一下我的程序:

    #include

    char words[2001][75]={};

    int doing[2001][2001];

    int number;

    int ok(char a[],char b[])

    {

    int i;

    for(i=0;inumber||start>number)return 0;

    if(max

  • 0
    @ 2009-09-17 20:57:28

    挺猥琐的

  • 0
    @ 2009-09-17 19:18:43

    一个字,水!

  • 0
    @ 2009-09-12 20:23:58

    打错三句,打漏一句,竟然过了9个点!!!弄得我根本看不出是怎么错的

    。。。。。。

    看来在学校机房效率比较低啊,回家一次就ac了

  • 0
    @ 2010-07-06 10:17:06

    最简单的dp,最长不下降序列……

    BS超过20行的……

  • 0
    @ 2009-08-26 19:48:50

    基础 DP

    Program P1028;

    var a:array[0..2000] of string;

    f:array[0..2000] of longint;

    i,j,n,m,ans:longint;

    Begin

    readln(n);

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

    for i:=1 to n do f[i]:=1;

    for i:=2 to n do

    for j:=1 to i-1 do

    if (pos(a[j],a[i])=1) and (f[j]+1>f[i]) then

    begin

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

    if f[i]>ans then ans:=f[i];

    end;

    writeln(ans);

    end.

  • 0
    @ 2009-08-20 10:19:30

    c++用strstr函数+指针+DP可以AC此题,不用狂搜+DP

    这是我的第一个用指针的程序啊

    关键部分:

    char *t;

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

    {t=strstr(a[i],a[j]);

    if((t==&a[i][0])&&(f[j]+1>f[i]))

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

    }

    }

  • 0
    @ 2009-08-19 15:22:09

    20题了,纪念~~~~~~~

  • 0
    @ 2009-08-16 17:37:35

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    #include

    using namespace std;

    char a[2001][10000];

    int n,maxn=0,f[2001];

    int pd(int p,int q)

    {

    int l,s;

    s=1;

    l=strlen(a[p])>strlen(a[q])?strlen(a[q]):strlen(a[p]);

    for(int i=0;i>n;

    for(int i=1;ia[i];

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

    if(pd(i,j)==1)

    if(f[j]+1>f[i])

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

    if(f[i]>maxn)

    maxn=f[i];

    }

    cout

  • 0
    @ 2009-08-16 16:07:13

    我日,调试过头,答案总是为0,想死!!!!!!!!!

    var

    i,j,m,n,max:integer;

    s,t:string;

    a:array[0..3000]of string;

    l:array[0..3000]of integer;

    p:array[0..3000]of integer;

    begin

    readln(n);

    for i:=1 to n do

    begin

    readln(a[i]);

    l[i]:=length(a[i]);

    if max=l[j])then if (copy(a[i],1,l[j])=a[j])

    then

    p[i]:=p[j]+1;

    for i:=1 to n do

    if m

  • 0
    @ 2009-08-16 15:49:13

    一道很好的动态规划。。。

    可以锻炼动归能力

    var

    n:integer;

    a:array[1..2000]of string;

    len:array[1..2000]of integer;

    l,i:integer;

    f:array[0..2000]of integer;

    function max(q:integer):integer;

    var i:integer;

    begin

    max:=0;

    for i:=1 to q do

    if (f[i]>max)and(a[i]=copy(a[q+1],1,length(a[i]))) then max:=f[i];

    end;

    begin

    readln(n);

    for i:=1 to n do

    begin

    readln(a[i]);

    len[i]:=length(a[i])

    end;

    for i:=1 to n do

    f[i]:=max(i-1)+1;

    l:=0;

    for i:=1 to n do

    if f[i]>l then

    l:=f[i];

    writeln(l);

    end.

  • 0
    @ 2009-08-16 15:37:11

    procedure doit;

    var i,j,x,y,z:longint;

    begin

    for i:=n downto 1 do

    begin

    max:=0;

    for j:=n downto 1 do

    if pos(a[j],a[i])=1 then inc(max);

    if max>max1 then max1:=max;

    end;

    end;

    纪念下自己20T了...- -感觉RP大爆 这也能过...

  • 0
    @ 2009-08-15 20:06:26

    这样的水题还难度2 几分钟就AC了 哎水水水水

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    水水水水水水水水水水水水水水水水水水水水水水水水水

    var

    v:array[1..2000]of string;

    dp:array[1..2000]of longint;

    n,i,j,ans:longint;

    begin

    fillchar(dp,sizeof(dp),0); ans:=0;

    readln(n);

    for i:=1 to n do

    begin

    readln(v[i]);

    for j:=i downto 1 do

    begin

    if pos(v[j],v[i])=1 then

    begin

    if dp[j]>dp[i] then dp[i]:=dp[j];

    end;

    end;

    inc(dp[i]);

    if dp[i]>ans then ans:=dp[i];

    end;

    writeln(ans);

    end.

    水水水水水水水水水水水水水水水水水水水水水水水水水

  • 0
    @ 2009-08-08 23:17:16

    類似于“最長子序列”

    定義兩個數組 s[存儲字符串],f:到第i條最多的條數

    f[i]=max{f[j] | 0

  • 0
    @ 2009-08-02 00:53:41

    数据太小了,我的程序在这可以对完,可在rqnoj里我只能对一半

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

  • 0
    @ 2009-07-31 10:33:44

    VAR x,i,now,worb,cc,enal:integer; c,ccc:char;

    xx:array[1..2000] of string[75]; xc:string[75];

    xxx:array[1..2000] of boolean;

    wor:array['a'..'z'] of integer;

    begin

    fillchar(xxx,sizeof(xxx),0);

    fillchar(wor,sizeof(wor),0);

    readln(x);

    now:=1;

    worb:=0;

    for i:=1 to x do readln(xx[i]);

    repeat

    for i:=1 to x do

    begin

    xc:=xx[i];

    inc(wor[xc[now]]);

    end;

    for c:='a' to 'z' do if wor[c]>worb then cc:=ord(c);

    for i:=1 to x do

    begin

    if (length(xx[i])

  • 0
    @ 2009-07-30 19:51:08

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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



    水水

    水水水

    水水水水

    水水水水水

    水水水水水水

    水水水水水水水

    水水水水水水水水

    水水水水水水水水水

    水水水水水水水水水水

    水水水水水水水水水水水

    水水水水水水水水水水水水

    水水水水水水水水水水水水水

    水水水水水水水水水水水水水水

  • 0
    @ 2009-07-29 20:43:49

    我晕,这样的水题还有人贴AC证书。真是...

  • 0
    @ 2009-07-29 20:02:22

    procedure work;

    var

    i,j,k,n:integer;

    a:array[1..2000]of string;

    s:string;

    ans:array[1..2000]of integer;

    max:integer;

    begin

    readln(n);

    for i:=1 to n do begin readln(a[i]);ans[i]:=1;end;

    for i:=1 to n do

    for j:=i+1 to n do

    begin

    s:=copy(a[j],1,length(a[i]));

    if (s=a[i])and(ans[i]+1>ans[j])then ans[j]:=ans[i]+1;

    end;

    max:=0;

    for i:=1 to n do

    if ans[i]>max then max:=ans[i];

    writeln(max);

    end;

    begin

    work;

    end.

    我这样为什么会堆栈溢出呢?

信息

ID
1028
难度
4
分类
动态规划 | LIS 点击显示
标签
(无)
递交数
6000
已通过
2434
通过率
41%
被复制
9
上传者