题解

163 条题解

  • 0
    @ 2008-11-12 20:14:44

    随机化搜索

    哈哈

    支持



    ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

    var n,k,i,j,kk,dt,max,max2,max3:longint;

    s,s1:string;

    b:array[0..10000]of longint;

    function pd(x,y:longint):boolean;

    var i:longint;

    begin

    pd:=true;

    for i:=1 to y do if b[i]=x then pd:=false;

    end;

    begin

    readln(n,k);

    readln(s);

    randomize;

    max:=0;

    for i:=1 to 100000 do

    begin

    for j:=1 to k do b[j]:=0;

    for j:=1 to k do

    begin

    dt:=random(n-1)+1;

    if pd(dt,j-1) then b[j]:=dt;

    end;

    for kk:=1 to k-1 do

    for j:=kk+1 to k do

    if b[kk]>b[j] then

    begin

    dt:=b[kk];

    b[kk]:=b[j];

    b[j]:=dt;

    end;

    max2:=1;

    b[k+1]:=length(s);

    s1:=s;

    max3:=1;

    val(copy(s1,1,b[1]),max3);

    max2:=max3*max2;

    for j:=2 to k+1 do

    begin

    max3:=1;

    val(copy(s1,b[j-1]+1,b[j]-b[j-1]),max3);

    max2:=max3*max2;

    end;

    if max2>max then max:=max2;

    end;

    writeln(max);

    end.

    编译通过...

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

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

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

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

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

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

    动规 写法

    var i,j,k,n,max,m:longint;

    a:array[0..10000]of longint;

    f,da:array[0..1000,0..1000]of int64;

    s:string;

    begin

    readln(n,m);

    readln(s);

    for i:=1 to n do for j:=1 to n-i+1 do val(copy(s,i,j),da);

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

    for i:=2 to n do

    for j:=1 to i-1 do

    begin

    max:=1;

    for k:=1 to i-1 do

    if f[k,j-1]*da[k+1,i-k]>max then max:=f[k,j-1]*da[k+1,i-K];

    f:=max;

    end;

    writeln(f[n,m]);

    end.

    改到吐血 终于AC了!

    不支持 呵呵

    ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

  • 0
    @ 2008-11-12 14:05:28

    DP...空虚中...

    此题数据不需高精.PAS用LONGINT足够...不过还是写一下高精的比较好...

  • 0
    @ 2008-11-08 14:25:12

    program maxmu;

    type num=array[0..50]of integer;

    var s:array[1..40,1..40]of num;

    f:array[1..40,0..39]of num;

    tmp,ori:num;

    n,k,i,j,kx:longint;

    ch:char;

    function mul(a,b:num):num;

    var i,j,k,la,lb,l:longint;

    c:num;

    begin

    fillchar(mul,sizeof(mul),0);

    la:=a[0];lb:=b[0];

    for i:=1 to la do begin

    fillchar(c,sizeof(c),0);

    for j:=1 to lb do c:=a[i]*b[j];

    l:=i+j-1;if l=10 then begin

    inc(mul[j+1],mul[j] div 10);

    mul[j]:=mul[j] mod 10;

    end;

    end;

    if mul[l+1]>0 then inc(l);

    while mul[l]>=10 do begin

    inc(mul[l+1],mul[l] div 10);

    mul[l]:=mul[l] mod 10;

    end;

    mul[0]:=l;

    end;

    end;

    procedure swap(var a,b:integer);

    var t:integer;

    begin

    if ab then begin

    t:=a;a:=b;b:=t;

    end;

    end;

    function judge(a,b:num):boolean;

    var i:longint;

    begin

    judge:=false;

    if a[0]>b[0] then exit(true)

    else if a[0]b[i] then exit(true)

    else if a[i]

  • 0
    @ 2008-11-24 22:40:35

    写了很多,然后听到可以不用高精度。。。T_T

    program Agent;

    type

    bignum=array[0..500]of integer;

    var

    f,f1,g:array[1..40,1..40]of bignum;

    n,k:longint;

    a:bignum;

    procedure init;

    var

    i,x,y:longint;

    s:string;

    begin

    readln(n,k);

    a[0]:=n;

    read(s);

    for i:= 1 to n do a[i]:=ord(s[i])-48;

    end;

    function compare(a,b:bignum):bignum;

    var

    i,x,y:longint;

    begin

    if a[0]>b[0] then exit(a);

    if b[0]>a[0] then exit(b);

    for i:=a[0] downto 1 do

    begin

    if b[i]>a[i] then exit(b);

    if a[i]>b[i] then exit(a);

    end;

    exit(a);

    end;

    function mul(a,b:bignum):bignum;

    var

    i,x,y:longint;

    c:bignum;

    begin

    fillchar(c,sizeof(c),0);

    c[0]:=a[0]+b[0]-1;

    for x:= 1 to a[0] do

    for y:= 1 to b[0] do inc(c[x+y-1],a[x]*b[y]);

    for i:= 1 to c[0] do

    begin

    inc(c,c[i] div 10);

    c[i]:=c[i] mod 10;

    end;

    while c[c[0]+1]>0 do

    begin

    inc(c[0]);

    inc(c[c[0]+1],c[c[0]] div 10);

    c[c[0]]:=c[c[0]] mod 10;

    end;

    exit(c);

    end;

    procedure dl;

    var

    i,x,y,t:longint;

    begin

    for x:= 1 to n do

    for y:= x to n do

    begin

    g[x,y][0]:=y-x+1;

    t:=1;

    for i:= y downto x do

    begin

    g[x,y][t]:=a[i];

    inc(t);

    end;

    end;

    f1:=g;

    end;

    procedure main;

    var

    t,m,i,x,y:longint;

    c1:bignum;

    begin

    dl;

    fillchar(c1,sizeof(c1),0);

    for m:=1 to k do

    begin

    fillchar(f,sizeof(f),0);

    for x:= 1 to n do

    for y:= x to n do

    for t:= x to y-1 do

    begin

    c1:=mul(f1[x,t],g[t+1,y]);

    f[x,y]:=compare(c1,f[x,y]);

    end;

    f1:=f;

    end;

    end;

    procedure print;

    var

    i,x,y:longint;

    begin

    for i:= f[1,n][0] downto 1 do write(f[1,n][i]);

    end;

    begin

    init;

    main;

    print;

    end.

  • 0
    @ 2009-07-03 13:10:44

    咋看数据规模,回溯即可。

    方程:f表示前I个数中插入J个*号的最优值。

    f:=max(f[k,j-1]*num[k+1,i){k:=j to i-1);

  • 0
    @ 2008-11-04 20:21:09

    DP 设f(i,j)为前i个数,添加j个乘号的最大乘积,则

    f(i,j)=max{f(i-k,j-1)*num(i-k+1,i)},目标:f(n,k)。

    其中1

  • 0
    @ 2008-11-03 09:12:04

    数据暴弱,extended就够了

  • 0
    @ 2008-11-01 15:44:55

    用DP

    C语言

    不管是long long类型还是int类型……第二个点都过不了……难道……还是得高精度?

  • 0
    @ 2008-10-31 09:25:59

    这个数据也太……没用高精度都能秒杀……

  • 0
    @ 2008-10-30 20:46:00

    我只想说,浪费了我的时间来写高精度。。!!!

    靠!

    算吧。。当复习复习··

  • 0
    @ 2008-10-28 23:10:03

    很想练dp,可是看了看那个数据量,不用搜索太对不起他了。

  • 0
    @ 2008-10-28 22:18:37

    太水了,裸搜,不用优化,不用高精度

  • 0
    @ 2008-10-22 09:40:38

    时间:O(k*(n^2))

    空间:O(n*k)

  • 0
    @ 2008-10-19 10:59:41

    编译通过...

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

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

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

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

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

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

  • 0
    @ 2008-10-15 20:56:12

    var

    ans:array[1..40,0..40,0..6] of extended;

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

    k,i,j,d,n,t,h,f:longint;

    s,s1:string;

    begin

    readln(n,t);

    read(s);

    for i:=1 to n do

    begin

    a[i]:=ord(s[i])-ord('0');

    ans:=a[i];

    end;

    for i:=1 to n do

    for j:=i+1 to n do

    ans:=a[j]+ans*10;

    for d:=1 to n-1 do

    for i:=1 to n-d do

    begin

    j:=i+d;

    for k:=i to j-1 do

    for h:=1 to t do

    begin

      for f:=0 to h-1 do

    if ans*ans[k+1,j,h-f-1]>ans then

      ans:=ans*ans[k+1,j,h-f-1];

    end;

    end;

    writeln(ans[1,n,t]:0:0);

    end.

  • 0
    @ 2008-10-04 15:10:26

    编译通过...

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

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

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

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

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

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

    才4个点?!!?

  • 0
    @ 2008-09-29 08:12:31

    var

    ans:array[1..40,0..40,0..6] of extended;

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

    k,i,j,d,n,t,h,f:longint;

    s:string;

    begin

    readln(n,t);

    read(s);

    for i:=1 to n do

    begin

    a[i]:=ord(s[i])-ord('0');

    ans:=a[i];

    end;

    for i:=1 to n do

    for j:=i+1 to n do

    ans:=a[j]+ans*10;

    for d:=1 to n-1 do

    for i:=1 to n-d do

    begin

    j:=i+d;

    for k:=i to j-1 do

    for h:=1 to t do

    begin

    for f:=0 to h-1 do

    if ans*ans[k+1,j,h-f-1]>ans then

    ans:=ans*ans[k+1,j,h-f-1];

    end;

    end;

    writeln(ans[1,n,t]:0:0);

    end.

    extended 也可过

    哈哈!!!!

  • 0
    @ 2008-09-27 18:34:40

    1次ac

    O(n^3*m)

    第72个AC!

    用DP写的。。。。。。

  • 0
    @ 2008-09-09 17:34:15

    为什么裸搜可以?

  • 0
    @ 2008-08-28 11:32:48

    编译通过...

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

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

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

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

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

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

    突然发现

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

    s:string;

    max,max1:qword;

    procedure try(s1:string;nb:integer);

    var oi,oj,oa,ob:integer;

    begin

    if (s1='') and (nb=0) then begin if maxlength(s1) then exit;

    if (length(s)>0)and(nb=0) then exit;

    for oi:=1 to length(s1) do

    begin

    val(copy(s1,1,oi),oa,ob);

    if oa0 then

    begin

    max1:=max1*oa;nb:=nb-1;

    try(copy(s1,oi+1,length(s1)-i),nb);

    nb:=nb+1;max1:=max1 div oa;

    end;

    end;

    end;

    begin

    readln(n,k);

    readln(s);

    max:=0;max1:=1;

    if s='0' then writeln(0)

    else

    begin

    try(s,k+1);

    writeln(max);

    end;

    end.

    AC……

    是DFS好

    还是

    ……

    我的RP高~?

信息

ID
1347
难度
2
分类
动态规划 点击显示
标签
递交数
3180
已通过
1810
通过率
57%
被复制
20
上传者