#include
<
cstdio
>
#include
<
cstring
>
#include
<
cstdlib
>
using
namespace
std;
typedef
char
string
[
85
];
int
N;
string
s;
int
f[
85
][
85
],a[
85
][
85
];
bool
check(
int
l1,
int
r1,
int
l2,
int
r2)
{
while
(l1
<
r1
&&
s[l1]
==
'
0
'
) l1
++
;
while
(l2
<
r2
&&
s[l2]
==
'
0
'
) l2
++
;
if
(r1
-
l1
+
1
>
r2
-
l2
+
1
)
return
1
;
if
(r1
-
l1
+
1
<
r2
-
l2
+
1
)
return
0
;
for
(;l1
<=
r1,l2
<=
r2;
++
l1,
++
l2)
if
(s[l1]
>
s[l2])
return
1
;
else
if
(s[l1]
<
s[l2])
return
0
;
return
0
;
}
void
out
(
int
k,
int
i)
{
if
(i
==
0
)
return
;
out
(k
-
i,a[k][i]);
for
(
int
j
=
k
-
i
+
1
;j
<=
k;
++
j)
printf(
"
%c
"
,s[j]);
if
(k
!=
N) printf(
"
,
"
);
}
int
main()
{
freopen(
"
incsq.in
"
,
"
r
"
,stdin);
freopen(
"
incsq.out
"
,
"
w
"
,stdout);
scanf(
"
%s
"
,s
+
1
);
N
=
strlen(s
+
1
);
memset(f,
128
,
sizeof
(f));
for
(
int
i
=
1
;i
<=
N;
++
i){
f[i][i]
=
1
; a[i][i]
=
0
;
}
for
(
int
i
=
1
;i
<=
N;
++
i)
for
(
int
j
=
1
;j
<=
i;
++
j)
for
(
int
k
=
1
;k
<=
i
-
j;
++
k)
if
(check(i
-
j
+
1
,i,i
-
j
-
k
+
1
,i
-
j))
if
(f[i][j]
<
f[i
-
j][k]
+
1
){
f[i][j]
=
f[i
-
j][k]
+
1
;
a[i][j]
=
k;
}
int
i
=
1
;
for
(
int
k
=
2
;k
<=
N;
++
k)
if
(f[N][k]
>
f[N][i]) i
=
k;
out
(N,i);
printf(
"
\n
"
);
return
0
;
}
posted on 2009-07-27 14:31
xfstart07 阅读(130)
评论(0) 编辑 收藏 引用