C - Low Elements
从前往后维护一个最长下降子序列
D - Handstand 2
设f[a][b]代表当前第一个数字为a第二个数字为b的数总个数
递推一下就可以。注意a==b的情况。
# -*- coding: utf-8 -*-
# @time : 2023/6/2 13:30
# @file : atcoder.py
# @software : PyCharm
import bisect
import copy
import sys
from itertools import permutations
from sortedcontainers import SortedList
from collections import defaultdict, Counter, deque
from functools import lru_cache, cmp_to_key
import heapq
import math
sys.setrecursionlimit(1000)
def main():
items = sys.version.split()
if items[0] == '3.10.6':
fp = open("in.txt")
else:
fp = sys.stdin
n = int(fp.readline())
d = [[0] * 10 for _ in range(10)]
ans = 0
for i in range(1, n + 1):
s = str(i)
a, b = int(s[0]), int(s[-1])
d[a][b] += 1
if a != b:
ans += d[b][a] * 2
else:
ans += (d[a][a] - 1) * 2 + 1
print(ans)
if __name__ == "__main__":
main()
E - Flatten
数论题,需要分解质因数和逆元,然而python改变了一切
# -*- coding: utf-8 -*-
# @time : 2023/6/2 13:30
# @file : atcoder.py
# @software : PyCharm
import bisect
import copy
import sys
from itertools import permutations
from sortedcontainers import SortedList
from collection

文章介绍了如何使用递推方法解决C-LowElements中的最长下降子序列问题,以及在数论题目中应用分解质因数、逆元和容斥原理来计算LCM和满足特定条件的方案数。
最低0.47元/天 解锁文章
419

被折叠的 条评论
为什么被折叠?



