ak日记 831 dxm
作者:互联网
import sys from math import inf line = sys.stdin.readline().strip() vs = list(map(int, line.split())) n, k = vs[0], vs[1] line = sys.stdin.readline().strip() vs = list(map(int, line.split())) dp = [[0]*n for _ in range(n)] ans = 0 for i in range(n-1, -1, -1): dp[i][i] = (vs[i], vs[i]) if k==1: ans+=1 for j in range(i+1, n): minv, maxv = dp[i+1][j] minv = min(minv, vs[i]) maxv = max(maxv, vs[i]) dp[i][j] = (minv, maxv) if minv*k == maxv:ans += 1 print(ans)
import sys from math import inf from functools import lru_cache class Solution: def slove(self, n, m, k, x, grid): @lru_cache(None) def dfs(i=0, j=0, total=0): ans = False if i == n - 1 and j == m - 1 and total + grid[i][j] == x: ans = True if i < n and j < m: ans = ans or dfs(i + 1, j, total + grid[i][j]) ans = ans or dfs(i, j + 1, total + grid[i][j]) return ans return dfs() sol = Solution() T = int(sys.stdin.readline().strip()) for _ in range(T): line = sys.stdin.readline().strip() vs = list(map(int, line.split())) n, m, k, x = vs[0], vs[1], vs[2], vs[3] grid = [] for _ in range(n): line = sys.stdin.readline().strip() vs = list(map(int, line.split())) grid.append(vs) if (sol.slove(n, m, k, x, grid)): print("yes") else: print("no")
import sys from math import inf MOD = 10**9+7 n = int(sys.stdin.readline().strip()) dp = [[[0]*2 for _ in range(2)] for _ in range(n+1)] #dp[i][j][k] i位以 j k=0非1 j k=1 1结尾的最大个数 00 01 10 11 dp[1] = [[8, 1], [0, 0]] for i in range(2, n+1): dp[i][0][0] = ((dp[i-1][0][0] + dp[i-1][1][0])*8)%MOD dp[i][0][1] = (dp[i-1][0][0])%MOD dp[i][1][0] = (dp[i-1][0][1]*8)%MOD dp[i][1][1] = 0 ans = sum([sum(dp[-1][i]) for i in range(2)])%MOD print(ans)
比较简单 不到一小时选择+算法就做完了~
标签:831,ak,range,sys,dxm,vs,ans,line,dp 来源: https://www.cnblogs.com/yuelien/p/16644354.html