北京网站推广优化,公众号怎么引流推广,最好网站建设公司哪家好,门头广告设计图片陷入了“会做#xff0c;但不完全会做”的状况 C 水题#xff0c;排序找中间数两边的差值 D 组合数学 求把n个相同的球分到m个相同的盒子#xff0c;1每个盒子至少一个球2每个盒子球不限的组合数 空挡插隔板法#xff0c;高中数学
# -*- coding: utf-8 -*-
# time : 2…陷入了“会做但不完全会做”的状况 C 水题排序找中间数两边的差值 D 组合数学 求把n个相同的球分到m个相同的盒子1每个盒子至少一个球2每个盒子球不限的组合数 空挡插隔板法高中数学
# -*- coding: utf-8 -*-
# time : 2023/6/2 13:30
# author : yhdutongwoo.cn
# desc :
# file : atcoder.py
# software : PyCharm
import bisect
import copy
import sys
from sortedcontainers import SortedList
from collections import defaultdict, Counter, deque
from functools import lru_cache, cmp_to_key
import heapq
import math
sys.setrecursionlimit(100010)mod 10 ** 9 7def pw(a, x):if x 0:return 1temp pw(a, x 1)if x 1:return temp * temp * a % modelse:return temp * temp % moddef inv(x):return pw(x, mod - 2)def main():items sys.version.split()if items[0] 3.10.6:fp open(in.txt)else:fp sys.stdinn, k map(int, fp.readline().split())R, B n - k, kdef cmb(x, y):if x y:return 0return fac[x] * inv(fac[y]) * inv(fac[x - y]) % modfac [1] * 5005for i in range(2, 5005):fac[i] fac[i - 1] * i % modfor i in range(1, B 1):ans_r cmb(R 1, i)ans cmb(B - 1, i - 1) * ans_r % modprint(ans)if __name__ __main__:main()
E 一开始用dfs去求3步能访问到的点对明显TLE 分层图求最短路 原图分为3层每个点拆成 V 0 , V 1 , V 2 V_0,V_1,V_2 V0,V1,V2 假如 ( u , v ) (u,v) (u,v)间有一条有向边 把边拆成 ( u 0 , v 1 ) , ( u 1 , v 2 ) , ( u 2 , v 3 ) (u_0,v_1),(u_1,v_2),(u_2,v_3) (u0,v1),(u1,v2),(u2,v3) 走三的倍数步能回到0层这样只要能走到 T 0 T_0 T0点就有解
# -*- coding: utf-8 -*-
# time : 2023/6/2 13:30
# author : yhdutongwoo.cn
# desc :
# file : atcoder.py
# software : PyCharm
import bisect
import copy
import sys
from sortedcontainers import SortedList
from collections import defaultdict, Counter, deque
from functools import lru_cache, cmp_to_key
import heapq
import math
sys.setrecursionlimit(100010)def main():items sys.version.split()if items[0] 3.10.6:fp open(in.txt)else:fp sys.stdinn, m map(int, fp.readline().split())g [[] for _ in range(n * 3)]for i in range(m):u, v map(int, fp.readline().split())u, v u - 1, v - 1u0, u1, u2 u, u n, u 2 * nv0, v1, v2 v, v n, v 2 * ng[u0].append(v1)g[u1].append(v2)g[u2].append(v0)S, T map(int, fp.readline().split())S, T S - 1, T - 1vis [-1] * (3 * n)qu deque()qu.append(S)vis[S] 0while qu:cur qu.popleft()if cur T:breakfor v in g[cur]:if vis[v] -1:vis[v] vis[cur] 1qu.append(v)if vis[T] -1:print(-1)else:print(vis[T] // 3)if __name__ __main__:main()
F 分块 重要的是想清楚每一块代表的数字