# Topcoder：SRM 708 算法题解

### 解题思路及代码

##### 250分题解：SafeBetting

import math,string,itertools,fractions,heapq,collections,re,array,bisect
class SafeBetting:
def minRounds(self, a, b, c):
return math.ceil(math.log(float(c-a)/(b-a),2))
##### 500分题解：BuildingStrings

class BuildingStrings:
def findAny(self, K):
S_26='abcdefghijklmnopqrstuvwxyz'
S_1300='abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx'
N_1300=K/1300
K=K-N_1300*1300
N_50=K/50
K=K-N_50*50
N_1=K
ret=[]
ret+=[S_1300 for i in range(N_1300)]
if N_50>0:
S_50k=S_26[:N_50]+'a'*(50-N_50)
ret+=[S_50k]
#print ret
S_1='a'*N_1
ret+=[S_1]
#print ret
return tuple(ret)
##### 1000分题解：PalindromicSubseq2

class PalindromicSubseq2:
def dynamicplan(self,s):
N=len(s)
#dp={j:{i:0 for i in range(N) if i>j} for j in range(N)}
dp=[[0 for i in range(N)] for j in range(N)]
for i in range(N):
dp[i][N-1]=1
for j in range(N):
dp[0][j]=1
for i in range(1,N):
for j in range(N-2,i-1,-1):
if s[i-1]==s[j+1]:
dp[i][j]=dp[i-1][j]+dp[i][j+1]
else:
dp[i][j]=dp[i-1][j]+dp[i][j+1]-dp[i-1][j+1]
return dp
def solve(self, s):
N=len(s)
dp=self.dynamicplan(s)
count=0
for i in range(N):
X_i=dp[i][i]
#print X_i,
count_i=(i+1)*X_i%1000000007
count^=count_i
return count

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120