主题:回文数
wzftz1966
[专家分:0] 发布于 2007-07-15 15:45:00
请那位大虾给帮忙!!!!
求正整数K的所有折分并统计回文数列的个数。[em18]
最后更新于:2007-07-15 15:48:00
回复列表 (共3个回复)
沙发
Matodied [专家分:7560] 发布于 2007-07-15 20:41:00
DECLARE SUB pri ()
DECLARE SUB pdhw ()
CLS
DIM SHARED k, total, t
INPUT k
DIM SHARED a(k)
s = 0: t = 1
DO
a(t) = a(t) + 1: s = s + a(t)
IF s >= k THEN
IF s = k THEN CALL pri: CALL pdhw
s = s - a(t): t = t - 1
IF t = 0 THEN EXIT DO
s = s - a(t)
ELSE
t = t + 1: a(t) = 0
END IF
LOOP UNTIL t = 0
PRINT "hw Total="; total
END
SUB pdhw
f = 1
FOR i = 1 TO INT(t / 2)
IF a(i) <> a(t + 1 - i) THEN f = 0: EXIT FOR
NEXT i
total = total + f
END SUB
SUB pri
PRINT k; "=";
FOR i = 1 TO t - 1: PRINT a(i); "+"; : NEXT i
PRINT a(t)
END SUB
板凳
QB爱好者 [专家分:370] 发布于 2007-08-28 13:30:00
cls
input n
print 2^(n\2)
end
[size=2][size=3][size=4][size=3][size=2](为什么有规律请自己分析,如果光是n的一种方法不算则要减一)[/size][/size][/size][/size][/size]
3 楼
我的电脑 [专家分:990] 发布于 2007-09-25 13:57:00
DECLARE SUB pri ()
DECLARE SUB pdhw ()
CLS
DIM SHARED k, total, t
INPUT k
DIM SHARED a(k)
s = 0: t = 1
DO
a(t) = a(t) + 1: s = s + a(t)
IF s >= k THEN
IF s = k THEN CALL pri: CALL pdhw
s = s - a(t): t = t - 1
IF t = 0 THEN EXIT DO
s = s - a(t)
ELSE
t = t + 1: a(t) = 0
END IF
LOOP UNTIL t = 0
PRINT "hw Total="; total
END
SUB pdhw
f = 1
FOR i = 1 TO INT(t / 2)
IF a(i) <> a(t + 1 - i) THEN f = 0: EXIT FOR
NEXT i
total = total + f
END SUB
SUB pri
PRINT k; "=";
FOR i = 1 TO t - 1: PRINT a(i); "+"; : NEXT i
PRINT a(t)
END SUB
我来回复