for _ inrange(n*n): x,y,v=list(map(int,input().split())) if v==0and x==0and y==0: break m[x][y]=v
dp=[[[[0]*(n+1) for _ inrange(n+1)] for _ inrange(n+1)] for _ inrange(n+1)]
for i inrange(1,n+1): for j inrange(1,n+1): for h inrange(1,n+1): for k inrange(1,n+1): dp[i][j][h][k]=max( dp[i-1][j][h-1][k], dp[i-1][j][h][k-1], dp[i][j-1][h-1][k], dp[i][j-1][h][k-1] )+m[i][j]+m[h][k] if i==h and j==k: dp[i][j][h][k]-=m[h][k] print(dp[n][n][n][n])
T=int(input()) # n=100 defcheck(x,lst): iflen(lst)==0: returnFalse dp=[False]*(x+1) dp[0]=True for num in lst: for index,item inenumerate(dp): if index-num>=0: dp[index]|=dp[index-num] if dp[x]: returnTrue return dp[x] for _ inrange(T): n=int(input()) nums=list(map(int,input().split())) nums.sort(reverse=True) temp=0 for index,item inenumerate(nums): if check(item,nums[index+1:]): temp+=1 print(n-temp)
deffindx(x): if parent[x]!=-1: return findx(parent[x]) return x
defmerge(a,b): a_p=findx(a) b_p=findx(b) if a_p!=b_p: parent[a_p]=b_p
values=[] for _ inrange(m): a,b,c=list(map(int,input().split())) values.append((a,b,c)) values=sorted(values,key=lambda x:x[2],reverse=True)
disfriend=[0]*(n+1)
defsolve(): for a,b,c in values: if findx(a)==findx(b): print(c) returnTrue if disfriend[a]==0: disfriend[a]=b else: merge(disfriend[a],b) if disfriend[b]==0: disfriend[b]=a else: merge(disfriend[b],a) ifnot solve(): print(0)
# 矩阵相乘 def mul(A, B): # A:m*n, B:n*p 结果m*p m = len(A) n1 = len(A[0]) n2 = len(B) p = len(B[0]) if n1 !=n2: return n = n1= n2 ans = [] # 初始化ans for i in range(m): ans.append([0]*p) # 都用同一个变量row = [0]*p,会同时修改,所以不用同一个变量 for i in range(m): for j in range(p): temp = 0 for q in range(n): temp += A[i][q]*B[q][j] temp%=9999991 ans[i][j] = temp return ans def fib(n): if n==0: return 0 elif n==1 or n==2: return 1 base = [[1,1],[1,0]] n = n-2 ans = [[1,0],[0,1]] while n: if n&1: ans = mul(base,ans) base = mul(base,base) n = n>>1 # temp=mul([[1,1]],ans) # print(temp[0][0],ans[0][0] + ans[0][1]) return ans[0][0] + ans[0][1] if __name__=='__main__': # 前20个斐波那契数列 # 0是第0个 # 2023040313301730 print(fib(2023040313301730)%9999991) # for i in range(20230403%1330173): # print(fib(i),end=' ')