当前位置: 首页 > news >正文

AtCoder ABC154

C - Distinct or Not
签到题,注意大小写和以前的不一样

D - Dice in Line
签到题2,用个窗口即可

E - Almost Everywhere Zero
数位DP(搜索)的例题
pos表示当前搜索到的位置(开始为0,结束为n)
num表示已经使用的非0数字个数
cap表示搜索是否被限制,当之前搜索的数字比s小时cap=0,否则cap=1,开始时cap=1

# -*- coding: utf-8 -*-
# @time     : 2023/6/2 13:30
# @file     : atcoder.py
# @software : PyCharmimport 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.stdins = fp.readline().strip()n = len(s)k = int(fp.readline())@lru_cache(None)def get(pos, cap, num):if num == k:return 1if pos == n:return 0ret = 0si = int(s[pos])if cap == 0:ret += get(pos + 1, cap, num)ret += get(pos + 1, cap, num + 1) * 9else:if si == 0:ret += get(pos + 1, cap, num)else:ret += get(pos + 1, cap, num + 1)ret += get(pos + 1, 0, num + 1) * (si - 1)ret += get(pos + 1, 0, num)return retans = get(0, 1, 0)print(ans)if __name__ == "__main__":main()

F - Many Many Paths

组合数学
显见
1.每个(r,c)点上的数都是一个组合数 C ( r + c , c ) C(r+c,c) C(r+c,c)
2.可以用容斥原理将ans拆成 g ( r 2 , c 2 ) − g ( r 2 , c 1 − 1 ) − g ( r 1 − 1 , c 2 ) + g ( r 1 − 1 , c 1 − 1 ) g(r_2,c_2)-g(r_2,c_1-1)-g(r_1-1,c_2)+g(r_1-1,c_1-1) g(r2,c2)g(r2,c11)g(r11,c2)+g(r11,c11)
其中 g g g函数是从(0,0)到(r,c)点的所有组合数的和。
将g按列分解(行也一样)
得到 g = C ( 0 , 0 ) + C ( 1 , 0 ) + . . . + C ( r , 0 ) + C ( 1 , 1 ) + C ( 2 , 1 ) + . . . + C ( r + 1 , 1 ) + . . . . C ( 1 + c , c ) + C ( 2 + c , c ) + . . . + C ( r + c , c ) g=C(0,0)+C(1,0)+...+C(r,0)+\\ C(1,1)+C(2,1)+...+C(r+1,1) + \\ ....\\ C(1+c,c)+C(2+c,c)+...+C(r+c,c) g=C(0,0)+C(1,0)+...+C(r,0)+C(1,1)+C(2,1)+...+C(r+1,1)+....C(1+c,c)+C(2+c,c)+...+C(r+c,c)
每一行都可以规约为 C ( r + c + 1 , c + 1 ) C(r+c+1, c+1) C(r+c+1,c+1)
这样可以写出一个 O ( n ) O(n) O(n)算法

# -*- coding: utf-8 -*-
# @time     : 2023/6/2 13:30
# @file     : atcoder.py
# @software : PyCharmimport 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.stdinr1, c1, r2, c2 = map(int, fp.readline().split())mod = 10 ** 9 + 7fac = [1] * 2000002iv = [1] * 2000002for i in range(1, 2000002):fac[i] = fac[i - 1] * i % moddef pw(a, x):if x == 1:return atemp = pw(a, x >> 1)if x & 1:return temp * temp * a % modelse:return temp * temp % modiv[1000001] = pw(fac[1000001], mod - 2)for i in range(1000000, -1, -1):iv[i] = (iv[i + 1] * (i + 1)) % moddef cmb(x, y):return fac[x] * iv[y] * iv[x - y] % moddef get(r, c):ret = 0for i in range(1, r + 2):ret = (ret + cmb(i + c, c)) % modreturn reta0, a1, a2, a3 = get(r2, c2), get(r1 - 1, c2), get(r2, c1 - 1), get(r1 - 1, c1 - 1)ans = (a0 - a1 - a2 + a3) % modprint(ans)if __name__ == "__main__":main()
http://www.lryc.cn/news/229961.html

相关文章:

  • 可以非常明显地感受到,一场有关直播带货的暗流正在涌动
  • C++中的四种构造函数
  • 通过反射获取某个对象属性是否存在,并获取对象值
  • 【MySQL】存储过程与函数
  • 【数学】Pair of Topics—CF1324D
  • Qt文档阅读笔记-Fetch More Example解析
  • QtC++与QTableView详解
  • HG/T 6002-2022 氟树脂粉末涂料检测
  • 【java】idea可以连接但看不到database相关的files
  • 信驰达科技加入车联网联盟(CCC),推进数字钥匙发展与应用
  • p9 Eureka-搭建eureka服务
  • 阶段七-Day01-SpringMVC
  • Python---集合中的交集 、并集 | 与差集 - 特性
  • C++调用lua脚本,包括全局函数绑定、类绑定,十分钟快速掌握
  • 快乐数[简单]
  • Spring源码阅读-ClassPathXmlApplicationContext
  • 考研分享第2期 | 中央财经大学管理科学跨考北大软微金融科技406分经验分享
  • Linux安装java jdk配置环境 方便查询
  • 惊群效应之Nginx处理
  • SpringBoot整合Ldap--超详细方法讲解
  • 【工程实践】Docker使用记录
  • FreeSwitch安装视频
  • SpringBoot3+Vue3+Mysql+Element Plus完成数据库存储blob类型图片,前端渲染后端传来的base64类型图片
  • 攻略 | 参与Moonbeam Ignite Ecosystem Tour
  • 【python自动化】Playwright基础教程(七)Keyboard键盘
  • Java读取文件内容写入新文件
  • 学习samba
  • 【Ansible】Ansible的Ad-hoc命令执行流程
  • Postgresql 常用整理
  • 如何在Jupyter Lab中安装不同的Kernel