163 条题解
-
0dev1 LV 7 @ 2009-06-25 18:13:20
秒了
program cheng;
var
f:array[1..40,1..6] of longint;
i,j,ans,k,m,n:longint;
a:array[1..40] of integer;
ss:string;
function yinzi(x,y:integer):longint;
var
i:integer;
begin
ans:=0;
for i:=x to y do
ans:=ans*10+a[i];
exit(ans);
end;
begin
readln(n,m);
readln(ss);
for i:=1 to n do
a[i]:=ord(ss[i])-48;
for i:=1 to n do
f:=yinzi(1,i);
for i:=2 to m+1 do
for j:=i to n do
for k:=j-1 downto 1 do
if f[k,i-1]*yinzi(k+1,j)>f[j,i] then
f[j,i]:=f[k,i-1]*yinzi(k+1,j);
writeln(f[n,m+1]);
end. -
02009-06-13 14:09:55@
读入数组后,从最后一个数开始搜索吧,这样优化程序,减少时间与空间
-
02009-06-12 20:24:49@
写一堆for就够了
何必那么麻烦呢 -
02009-06-10 17:42:27@
han!!!!!!
-
02009-05-15 22:32:35@
#include
#include
#include
int n,k;
long a[50][10]={0},c[100]={0},f[100]={0},p[100]={0};
char d[50];
void init()
{int i;
scanf("%d%d\n",&n,&k);
for(i=1;i -
02009-04-29 18:20:09@
var m,b,x,n,p,t,s,w,i:longint;
a:array[1..10000] of longint;
nn,aa,kk,xx:string;
begin
readln(n,p);
t:=1;
read(nn);
repeat
begin
a[t]:=a[t]+1;s:=s+a[t];
if s>=n then
begin
if (s=n) and (t=p+1) then
begin
w:=1;aa:=copy(nn,w,a[1]);val(aa,b);
for i:=2 to t do
begin
w:=w+a;val(copy(nn,w,a[i]),x);b:=b*x;
val(copy(nn,w,a[i]),x);str(x,xx);aa:=aa+' *'+xx;
end;
if b>m then begin m:=b;kk:=aa;end;
end;
s:=s-a[t];t:=t-1;s:=s-a[t];
end
else begin t:=t+1;a[t]:=0;end;
end;
until t=0;
write(m);
end. -
02009-04-28 18:45:45@
var
num:array[1..40,0..30]of longint;
a:array[1..40,0..30]of longint;
i,tt,j,n,m,x,man,code:longint;
s,ttt:string;
procedure change( i,j:longint; var p:string);
var
k:longint;
begin
p:='';
for k:=i to j do
p:=p+s[k];
end;
function max(l,r:longint):longint;
begin
if l>r then max:=l
else max:=r;
end;
begin
readln(n,m);
read(s);
fillchar(a,sizeof(a),0);
for i:=1 to n do
for j:=1 to n do
begin
tt:=0;
change(i,j,ttt);
val(ttt,tt,code);
num:=tt;
end;
for i:=1 to n do
a:=num[1,i];for i:=1 to n do
for j:=1 to m do
for x:=1 to i-1 do
begin
a:=max(a, a[x,j-1]*num[x+1,i]);
end;
write(a[n,m]);
end. -
02009-04-16 13:28:21@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
var a,b:array[0..100,0..100] of longint;
i,j,k,n,m:longint;
s:string;
begin
readln(n,m);
readln(s);
for i:=1 to n do a:=ord(s[i])-ord('0');
for i:=1 to n do
for j:=i+1 to n do
begin
a:=a*10+(ord(s[j])-ord('0'));
a[j,i]:=a;
end;
for i:=1 to n do b:=a[1,i];
{for i:=1 to 50 do for j:=0 to 50 do if b=0 then b:=1;}
for j:=1 to m do
for i:=2 to n dofor k:=1 to i-1 do
if (b -
02009-03-22 15:05:41@
var
st:string;
n,s,i,j,k:longint;
rec:array[0..50,0..50] of int64;
function cut(a,b:longint):longint;
var t:longint;
st1:string;
begin
st1:=copy(st,a,b-a+1);
val(st1,t);
exit(t);
end;
function search(a,b:longint):longint;
var
i,k,max,c:longint;
begin
max:=0;
if rec[a,b]-1 then begin exit(rec[a,b]);end;
for i:=a+1 to s-b+1 do
begin
k:=cut(a,i-1)*search(i,b-1);
if k>max then begin max:=k; c:=i;end;
end;
rec[a,b]:=max;
exit(max);
end;
begin
fillchar(rec,sizeof(rec),-1);
readln(s,n);
readln(st);
for i:=1 to s do
rec:=cut(i,s);
writeln(search(1,n));
end. -
02009-02-07 10:10:18@
数据弱,深搜也过得了.longint就够,才4个测试点
-
02009-01-20 15:21:00@
- -
-
02009-01-14 19:06:52@
大牛 看看 谢谢
var
xx:qword;
s,s1:string;
n,k,i,j,l:longint;
f:array[1..40,0..30] of qword;
begin
readln(n,k);
readln(s);
f[1,1]:=ord(s[1])-48;for l:=1 to k do
for i:=1 to n do
for j:=1 to i-1 do
if l0
then xx:=f[j,l-1]*xx;
if f -
02008-12-08 13:37:32@
program p1347;
var
o:array[1..40,1..7] of qword;
num:array[1..40,1..40] of qword;
n,k,code,i,j,x:integer;
s,s1:string;
function max(a,b:qword):qword;
begin
if a>b then exit(a) else exit(b);
end;
begin
readln(n,k);
readln(s);
fillchar(num,sizeof(num),0);
for i:=1 to n do
for j:=i to n do
begin
s1:=copy(s,i,j-i+1);
val(s1,num,code);
end;
for i:=1 to n do
o:=num;
for i:=n downto 1 do
for j:=2 to k+1 do
begin
for x:=n-j+1 downto i do
o:=max(o,num*o[x+1,j-1]);
end;
writeln(o[1,k+1]);
end. -
02008-12-03 16:00:50@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms
巨水!巨水!巨水!巨水!巨水!巨水!巨水!巨水!巨水!
var
l,n,k,i,j:longint;
s:char;
a:array[0..40]of longint;
d:array[0..41,0..41]of longint;
f:array[0..41,0..7]of longint;
begin
readln(n,k);
for i:=1to n do
begin
read(s);
a[i]:=ord(s)-ord('0');
d:=a[i];
end;
for i:=1to n do
for j:=i+1to n do
d:=d*10+a[j];
for i:=1to n do
f:=d[1,i];
for i:=1to k do
for j:=1to n do
for l:=i to j-1do
if f[l,i-1]*d[l+1,j]>f[j,i]
then f[j,i]:=f[l,i-1]*d[l+1,j];
writeln(f[n,i]);
end. -
02008-12-03 15:36:33@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms水题!水题!水题!水题!水题!水题!水题!水题!水题!
var
n,k,i,j,q,x:longint;
a:array[0..41]of longint;
f:array[-1..41,0..7]of longint;
s:string;
function shu(l,r:longint):longint;
var i:longint;
begin
shu:=0;
for i:=l to r do
shu:=shu*10+a[i];
end;
begin
readln(n,k);
k:=k+1;
readln(s);
filldword(f,sizeof(f) div 4,1);
for i:=1 to n do
a[i]:=ord(s[i])-48;
for i:=1 to n do
for j:=1 to k do
for q:=i-1 downto j-1 do
begin
x:=shu(q+1,i);
if x*f[q,j-1]>f
then f:=x*f[q,j-1];
end;
writeln(f[n,k]);
end. -
02008-11-29 14:07:37@
数据。。。。无语!!
-
02008-11-23 13:51:24@
注意
这一题一定要用字符串读入!
-
02008-11-22 13:35:36@
program p1182;
type xxx=array[1..240] of integer;
var a,b,c,d,k,n,l:longint;
p,t,ans:xxx;
x:array[1..6,1..40] of xxx;function chen(i,j:xxx;e:longint):xxx;
var a,l,b:longint;
t:xxx;
begin
l:=100;
while i[l]=0 do dec(l);
fillchar(t,sizeof(t),0);
for a:=1 to l do
for b:=1 to e do
begin
t[a+b-1]:=t[a+b-1]+i[a]*j;
t[a+b]:=t[a+b]+t[a+b-1] div 10;
t[a+b-1]:=t[a+b-1] mod 10;
end;chen:=t;
end;
function max(i,j:xxx):xxx;
var a,b,c:longint;
begin
a:=100;
while (a=0) or (i[a]=j[a]) do
begin
dec(a);
end;
if i[a]>j[a] then max:=i
else max:=j;
end;procedure init;
var s:string;
beginreadln(n,k);
readln(s);
for a:=1 to n do
p[a]:=ord(s[a])-48;
end;
procedure main(i,j:longint);
var a,b,c:longint;
s:xxx;
begin
for a:=1 to 240 do if x[a]0 then exit;for a:=i-1 to j-1 do
begin
fillchar(s,sizeof(s),0);
for b:=a+1 to j do
s[j-b+1]:=p;
main(i-1,a);
x:=max(x,chen(x,s,j-a));
end;
end;
begin
init;
fillchar(x,sizeof(x),0);
for a:=1 to n-k do
for b:=1 to a do
x[1,a][a-b+1]:=p;
main(k+1,n);
a:=100;
while x[k+1][n][a]=0 do dec(a);
for b:=a downto 1 do write(x[k+1][n]);
writeln;
end.
一次AC -
02008-11-12 21:42:19@
想了下,貌似数据有点小就写了integer,错了一次,日啊,我的ac率
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms -
02008-11-12 20:45:31@
哈哈,有了下面那只的前车之鉴,1次AC 哈哈哈。
原来是循环问题。无语……
预处理b数组
然后dp
for i:=2 to n do
for j:=1 to i-1 do
begin
max:=0;
for l:=1 to i-1 do
begin
if a[l,j-1]*b[l+1,i-l]>max then max:=a[l,j-1]*b[l+1,i-l];
end;
a:=max;
end;