AtCoder ABC152

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

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
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值