主题:难!!!!!!!!麻烦!!!!!!!
chenzhong
[专家分:250] 发布于 2005-08-22 20:09:00
我刚学编程20天,我妈就让我做高中的复赛题.[em10]
靠[em22]天书[em21]
没办法,麻烦大家看看下面一道题:
编写程序:设有一个长度为N的字符串,分成K+1个部分,使得K+1个部分的乘积最大.
大家评评理啊[em21]这个帖子我妈也要看的,麻烦大家向她说说正确的路线[em8]
回复列表 (共4个回复)
沙发
chenzhong [专家分:250] 发布于 2005-08-22 20:15:00
救命[em21][em21][em21][em21][em21][em21][em21][em21][em21][em21]
板凳
lzl1403 [专家分:1670] 发布于 2005-08-22 22:56:00
用动态规划做
3 楼
lzl1403 [专家分:1670] 发布于 2005-08-22 22:59:00
自己看程序理解一下吧
CONST
maxn=50;
VAR
f,g:array[0..maxn,0..maxn]of longint;
n,k,i,j,p,t1:longint;
code:integer;
s,s1:string;
BEGIN
readln(n,k);
readln(s);
for i:=1 to n do
for j:=1 to n do
begin
s1:=copy(s,i,j-i+1);
val(s1,g[i,j],code);
end;
for i:=1 to n do
f[i,0]:=g[1,i];
for i:=1 to n do
for j:=1 to i-1 do
begin
t1:=f[j,0]*g[j+1,i];
if t1>f[i,1]
then f[i,1]:=t1;
end;
for i:=2 to n do
for j:=1 to k do
begin
for p:=i downto 1 do
begin
if p<=j-1 then break;
t1:=f[p,j-1]*g[p+1,i];
if t1>f[i,j]
then f[i,j]:=t1;
end;
end;
writeln(f[n,k]);
END.
4 楼
lzl1403 [专家分:1670] 发布于 2005-08-22 23:00:00
应该是这题吧,NOIP2000提高组第二题
我来回复