那位大牛帮我看看

编译通过...

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

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

├ 测试数据 03:答案错误...

 ├ Hint: 注意考虑边界情况 ├ 标准行输出 7,3

 ├ 错误行输出 5,3

├ 测试数据 04:答案错误... ├ 标准行输出 5,7

 ├ 错误行输出 1,7

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

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

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

Unaccepted 有效得分:66 有效耗时:0ms

program du;

var

s:string;

b:array[1..20] of longint;

f:array[1..20] of longint;

a:array[1..20] of longint;

m,n,nn,k,i:integer;

procedure init;

var

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

begin

readln(s);

l:=length(s);

while l>0 do

begin

k:=pos(',',s);

inc(n);

if k=0 then

begin

val(s,a[n],code);

break;

end

else

begin

val(copy(s,1,(k-1)),a[n],code);

delete(s,1,k);

l:=length(s);

end;

end;

end;

function max(x,y:byte):byte;

begin

if x>y then

exit(x)

else exit(y);

end;

procedure jinsuo;

var

i,j,k:integer;

begin

i:=1;

j:=1;

for i:=1 to n do

if a[i]-1 then

begin

a[j]:=a[i];

a[i]:=-1;

inc(j);

end;

end;

procedure lcs;

var

i,j,k,kk:integer;

begin

for i:=(n-1) downto 1 do

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

begin

if (a[j]=f[i])and(a[i]>=0)and(a[j]>=0) then

b[i]:=j;

if (a[j]=0)and(a[j]>=0) then

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

end;

k:=1;

while b[k]k do

begin

a[k]:=-1;

k:=b[k];

end;

a[k]:=-1;

jinsuo;

n:=n-f[1];

inc(m);

end;

begin

init;

while n>0 do

begin

for i:=1 to n do

begin

b[i]:=i;

f[i]:=1;

end;

lcs;

if m=1 then

write(f[1],',');

end;

dec(m);

write(m);

end.

1 条评论

  • @ 2013-08-21 08:36:33

    #include <stdio.h>
    #define MIN -1

    int missile[20],i,j,f[25],n;

    int main()
    {
    void init();
    int longest_descend_sqnc();
    int longest_Ascend_sqnc();
    init();
    printf("%d,%d",longest_descend_sqnc(),longest_Ascend_sqnc()-1);
    return 0;
    }

    void init()
    {
    if (scanf("%d",missile) == 1)
    n = 1;
    else {
    n = 0;
    return;
    }
    while (scanf(",%d",missile+n) == 1)
    n++;
    }

    int *max_value;
    int *find_max(int *start,int *end)
    {
    max_value=start;
    while (++start <= end)
    if ((*start) > (*max_value))
    max_value = start;
    return max_value;
    }

    int longest_descend_sqnc()
    {
    f[0] = 1;
    for (i = 1;i < n;i++)
    for (j = 0,f[i]=1;j < i;j++)
    if ((missile[i] <= missile[j]) && (f[j]+1 >= f[i]))
    f[i] = f[j]+1;
    return *find_max(f,f+n-1);
    }

    int longest_Ascend_sqnc()
    {
    f[0] = 1;
    for (i = 1;i < n;i++)
    for (j = 0,f[i]=1;j < i;j++)
    if ((missile[i] > missile[j]) && (f[j]+1 >= f[i]))
    f[i] = f[j]+1;
    return *find_max(f,f+n-1);
    }

  • 1

信息

ID
1303
难度
6
分类
动态规划 | 单调性DP 点击显示
标签
递交数
7594
已通过
2015
通过率
27%
被复制
12
上传者