文章分类 - OI题目
摘要:/* 一棵二叉树 用三种颜色染色 相邻必须不同 且 若有两个子节点 三点互不相同 dp[u][0/1/2] u染成0/1/2 u的子树中绿色最多有几个 f[u][0/1/2] u染成0/1/2 u的子树中绿色最少有几个 ->1son dp[u][0]=max(dp[v][1],dp[v][2])+1
阅读全文
posted @ 2023-11-08 14:54
JMXZ
摘要:/* 求距离每一个点 0~k的 值 之和 f[u][i] 距离 u dis==i 的 val和(f[u][]的前缀和很难写) pre-dfs-> f[u][i]=sum(f[v][i-1])->u的子树内 f[u][i]=f[fa[u]][i-1]+f[u][i]-sum(f[u][0~i-2])
阅读全文
posted @ 2023-11-08 14:00
JMXZ
摘要:https://www.luogu.com.cn/problem/solution/P4929 /* */ /* 3 3 1 0 1 1 1 0 0 1 1 No Solution! 3 3 0 0 1 1 0 0 0 1 0 2 1 3 */ #include<cstdio> #include<i
阅读全文
posted @ 2023-11-08 09:43
JMXZ
摘要:/* https://www.luogu.com.cn/problem/P2534 一串数字1-n 每次可以反转1-k 的区间 问最少要处理几次 搜索树非常大-> A*+。。->IDE 估价函数选定 最好尽可能的小一些保证正确性 乐观估价<=实际大小 1.计数不同 显然不符合 2.有几个单调序列 5
阅读全文
posted @ 2023-10-29 15:03
JMXZ
摘要:/* https://www.luogu.com.cn/problem/P2324 从初始状态的棋盘变化到 目标棋盘 步数 IDE 算法 :A*+迭代加深算法 A* 乐观估价函数 每次从状态中 选出 t+h() 最小的进行更新 -> queue IDE -> dfs + 乐观估价函数 t(alrea
阅读全文
posted @ 2023-10-29 14:08
JMXZ
摘要:/*https://www.luogu.com.cn/problem/P3067 1~an 找出子集 且子集可以 分成两部分 和相同 的 小子集的并 折半搜索 本质是 拆分问题规模 用 O(N^2) 算法解决问题 dfs 1~n>>1 ai-bi 的种类 +dfs n>>1+1~n ci-di 若
阅读全文
posted @ 2023-10-28 17:51
JMXZ
摘要://URL:https://www.luogu.com.cn/problem/P4799 /* 1-4:dfs n<=20 m<=1e18 O(2^20) ÍêÈ«¿ÉÒÔ½ÓÊÜ 5-7:dp n=40 m=1e6 O(n*m) 8-10: dp+meet in middle O(2^20+1)
阅读全文
posted @ 2023-10-28 16:40
JMXZ
摘要://URL: https://www.luogu.com.cn/problem/P1312 /* 7*5的 棋盘 问最少几次可以清空 1.将(i,j) 左/右 交换 val-> null/val 2.行或列 有连续3个方块 会自动消掉 * * * * 包括这样的连通块 *** *** 3.每次操作后
阅读全文
posted @ 2023-10-28 11:18
JMXZ
摘要://https://www.luogu.com.cn/problem/P5195 /* st ed 经过选定的一类点 的距离最短 若直接搜索 floyd O(n^3) 超时 显然的双向搜索 减小复杂度 */ /* 8 4 4 1 0 0 0 0 1 0 0 0 0 1 0 1 0 0 0 2 1 1
阅读全文
posted @ 2023-10-28 08:06
JMXZ
摘要:// https://www.luogu.com.cn/problem/P3953/* dis(1,n)+k>=dist(1,n) 的方案数 30-最短路计数 <- dp 70-没有零环 自然的设 f[u][k] dist(1,u)==dis(1,u)+k 方案数 dis(1,u)+k+edge(u
阅读全文
posted @ 2023-10-28 07:33
JMXZ
摘要://URL: /* */ /* 4 5 6 . . . * . . . . * . . . . . . . . . . . 1 3 1 5 1 */ #include<cstdio> #include<iostream> #include<algorithm> #include<cmath> #in
阅读全文
posted @ 2023-10-24 05:09
JMXZ
摘要://URL: https://www.luogu.com.cn/problem/CF1837F /* 6 5 4 1 10 1 1 1 5 3 1 20 5 15 3 5 3 1 20 3 15 5 10 6 10 8 20 14 3 8 6 4 16 11 10 5 9 9 2 13 15 19
阅读全文
posted @ 2023-10-24 05:07
JMXZ
摘要:/* https://www.luogu.com.cn/problem/P1816 */ #include<cstdio> #include<iostream> #include<algorithm> #include<cmath> //#include<queue> //#include<vect
阅读全文
posted @ 2023-10-22 14:39
JMXZ
摘要:/* 3 2 3 1 0 1 3 1 2 3 2 2 1 3 0 2 1 5 3 1 2 5 4 5 1 3 3 2 3 1 4 3 3 2 1 2 1 2 */ /* 通过置换环 知道 答案是 所有 pi<i 的数 所以统计一下就可以了 O(N^2) 每一个数 对 每次询问的答案 的贡献 是一个区
阅读全文
posted @ 2023-10-22 09:50
JMXZ
摘要:/* set<matrix> s 存储地图状态 node{ matrix a; int t;} 乐观 估价函数 <= h()实际 283104765 123804765 h()==4 h*()=3 */ //283104765 4 #include<cstdio> #include<iostream
阅读全文
posted @ 2023-10-22 09:09
JMXZ
摘要:// LUOGU_RID: 129858861 /* A+b[b-1]>c[c]-1 A+b[b]-1<c[c-1] c[c-1]~~~~~~~~~~~ c[c]-1 A+b[b-1] A+b[b]-1 */ #include<cstdio> #include<iostream> #include<
阅读全文
posted @ 2023-10-22 09:04
JMXZ
摘要:// LUOGU_RID: 129683316 /* 6 3 1 2 3 5 1 2 3 4 5 2 2 3 1 1000000000 12 1 8 4 2 3 5 7 2 9 10 11 13 12 7 2 5 4 2 1 1 2 3 11 8 9 4 7 1 1 16 13 */ /* #inc
阅读全文
posted @ 2023-10-22 09:03
JMXZ
摘要:/* 7 5 abcde abxde 5 hello olleo 2 ab cd 7 aaaaaaa abbbbba 1 q q 6 yoyoyo oyoyoy 8 abcdefgh hguedfbh 1 2 3 9 0 2 6 */ #include<cstdio> #include<iostre
阅读全文
posted @ 2023-10-22 09:02
JMXZ
摘要:/* 题意: 将序列 交换排序成 逆序对 为 1 的排序 1.pre:置换环 pi -> a[pi] 最后会连成一个首尾相接的 环 答案是 n-cur 2.若 pi+1 / pi-1 已经在了 逆序对 ==1 ->flag flag==0 Ans=n-cur+1 flag==1 Ans=n-cur-
阅读全文
posted @ 2023-10-22 08:59
JMXZ
摘要:/* 5 3 3 100 2 1 14 91 2 13 36 16 6 73 8 22 100 0 26 72 176 */ /* */ #include<cstdio> #include<iostream> #include<algorithm> #include<cmath> #include<
阅读全文
posted @ 2023-10-22 08:37
JMXZ

浙公网安备 33010602011771号