ak日记 831 dxm
2022/8/31 23:22:57
本文主要是介绍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)
比较简单 不到一小时选择+算法就做完了~
这篇关于ak日记 831 dxm的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-21《鸿蒙HarmonyOS应用开发从入门到精通(第2版)》简介
- 2024-12-21后台管理系统开发教程:新手入门全指南
- 2024-12-21后台开发教程:新手入门及实战指南
- 2024-12-21后台综合解决方案教程:新手入门指南
- 2024-12-21接口模块封装教程:新手必备指南
- 2024-12-21请求动作封装教程:新手必看指南
- 2024-12-21RBAC的权限教程:从入门到实践
- 2024-12-21登录鉴权实战:新手入门教程
- 2024-12-21动态权限实战入门指南
- 2024-12-21功能权限实战:新手入门指南