2022年10月22日
摘要: f[i] 对于某个区间起点,状态转移到终点,要反过来枚举 i 方程不难想,两种情况 f[i] =max{ f[i+len[j] ] } f[i]= f[i+1]+1 #include <iostream> #include <algorithm> #include <cmath> using nam 阅读全文
posted @ 2022-10-22 13:57 towboat 阅读(19) 评论(0) 推荐(0)
摘要: 很水的区间dp #include <iostream> #include <cstring> #include <cmath> using namespace std ; const int N=502; int n,a[N],f[N][N]; int func(int l,int r){ if(l 阅读全文
posted @ 2022-10-22 12:12 towboat 阅读(11) 评论(0) 推荐(0)
  2022年10月21日
摘要: 两个货币系统 (n,a)(n,a) 和 (m,b)(m,b) 是等价的,当且仅当对于任意非负整数 xx,它要么均可以被两个货币系统表出,要么不能被其中任何一个表出。 现在网友们打算简化一下货币系统。他们希望找到一个货币系统 (m,b)(m,b),满足 (m,b)(m,b) 与原来的货币系统 (n,a 阅读全文
posted @ 2022-10-21 21:37 towboat 阅读(19) 评论(0) 推荐(0)
摘要: 有n个高度都为h的树(b[i]) ,树上的一些高度处有若干果实(比如b[i][h]==3) ,猫从任意的树顶部出发,可以 1.跳到任意其他的树上,高度将下降D 2.向下滑1个单位 问最多获得多少果实? 明显的dp 暴力程序 O(n^3) #include <iostream> #include <a 阅读全文
posted @ 2022-10-21 20:42 towboat 阅读(18) 评论(0) 推荐(0)
摘要: 对于1~n的整数组成的的排列,其中逆序对数为K的排列有几种 比如n=4,K=1时 下列3个数列逆序对数都为1, 1 2 4 3 ;1 3 2 4 ;2 1 3 4; f[i][j] 表示 1~i 的整数组成排列, 逆序对数为 j ,的排列个数 将第i个数字插入前i个位置中 ,可能产生 0~i-1 个 阅读全文
posted @ 2022-10-21 14:47 towboat 阅读(24) 评论(0) 推荐(0)
  2022年10月20日
摘要: 拓扑排序的过程很好描述: 每次访问入度=0 的所有点,删去,而且及时更新入度 在经过拓扑排序的图上求DAG最长路 #include <iostream> #include <queue> using namespace std ; const int N=1e6+3,M=2*N; int n,m; 阅读全文
posted @ 2022-10-20 21:33 towboat 阅读(17) 评论(0) 推荐(0)
摘要: int nxt[M],go[M],hd[N],all; void add(int x,int y){ go[++all]=y,nxt[all]=hd[x]; hd[x]=all; } 阅读全文
posted @ 2022-10-20 21:22 towboat 阅读(32) 评论(0) 推荐(0)
摘要: 翻译下题目: n个物品,每种物品有无限个,物品体积,现在一共取m个物品,且物品总体积不超V 问方案个数 纯粹的背包dp,没什么说的 #include <iostream> #include <cstring> using namespace std; const int N=503; int mod 阅读全文
posted @ 2022-10-20 20:08 towboat 阅读(25) 评论(0) 推荐(0)
摘要: 一个环上有n个点,价值 a[i],现在要选择m个点, 其中连续段的第一个元素的价值不算,求总和最大? 先考虑一条链 f[i][j][0/1] ,j 是目前选择了的点的个数, 0/1 当前点i 是否选择 状态转移: f[i][j][0]=max(f[i-1][j][0],f[i-1][j][1]) f 阅读全文
posted @ 2022-10-20 16:56 towboat 阅读(17) 评论(0) 推荐(0)
  2022年10月19日
摘要: 水题 这里记录个步骤 对某节点x,其子节点为y 求 a[y1]*(a[y2]+a[y3]+ ... +a[yn]) + a[y2]*(a[y1]+a[y3]+...a[yn]) + .... + a[yn]*(a[y1]+a[y2]+...+a[y(n-1)] ) 观察一下,很容易推出 answer 阅读全文
posted @ 2022-10-19 21:58 towboat 阅读(25) 评论(0) 推荐(0)