08 2020 档案
摘要:题目链接 k个式子相乘,把其中n个式子的x和m个式子的y选出来得到xn*ym项 Ckn*Ck-nm(n+m=k也就是1) 直接计算在取模后做除法需要乘法逆元,可以用杨辉三角求解 #include<bits/stdc++.h> using namespace std; int f[1010][1010
阅读全文
摘要:#抽屉原理 ##原理1: 把多于n+1个的物体放到n个抽屉里,则至少有一个抽屉里的东西不少于两件。 证明(反证法):如果每个抽屉至多只能放进一个物体,那么物体的总数至多是n×1,而不是题设的n+k(k≥1),故不可能。 ##原理2: 把多于mn+1(n不为0)个的物体放到n个抽屉里,则至少有一个抽屉
阅读全文
摘要:https://zhuanlan.zhihu.com/p/133818995 #递推公式 f[n]=(n-1)*(f[n-1]+f[n-2]) ##证明(这也配叫证明??? 第n个元素可以在前n-1个元素都是错排的情况下与其中一个元素交换位置(n不在就有的错排) 有(n-1)*f[n-1]种方案 第
阅读全文
摘要:https://www.luogu.com.cn/problem/P1040 中序遍历,左子树+根+右子树 对于区间l到r,枚举根结点i,再分别求解区间l到i-1和i+1到r 直接搜索程序很好看但是会t 可以改为记搜或动规 原题还需要求前序遍历,如果照常对于每个点存左儿子和右儿子,在l到r的区间中的
阅读全文
摘要:https://loj.ac/problem/10157 不同于战略游戏要求每边有人看守,即只能靠自己或者靠儿子 https://www.cnblogs.com/qwq-/p/13569330.html 本题要求每个点有人看守,即对于点root可以靠自己靠儿子或靠父亲 设dp[root][0/1/2
阅读全文
摘要:https://loj.ac/problem/10156 dp[i][0/1]表示以i为根的子树中,当i放(1)与不放(0)时最少放几个 由题意,树枝两端至少有一个放的,即父亲不放,所有儿子必须放;父亲放了,儿子放不放都行 注意从0开始编号 #include<bits/stdc++.h> using
阅读全文
摘要:https://loj.ac/problem/10155 因为一个i对应一个约数和,所以i向i的约数和连线会构成一棵树,i是i的约数和(a[i])的儿子 计算树的直径、最长链 设d1[i]表示i到 以i为根的子树中 的 叶子结点的最长距离,d2[i]表示次长,u[i]表示直径 d1[i]=max(d
阅读全文
摘要:https://www.luogu.com.cn/problem/P2014 设dp[i][j]表示以i为根的子树中(必须选i),选j门课获得的最多学分 先递归求出i的所有孩子的dp值 然后背包 枚举儿子(物品)枚举j(容量)再枚举儿子子树中选几门(决策)(注意倒序) #include<bits/s
阅读全文
摘要:https://www.luogu.com.cn/problem/P2015 设f[i][j]表示以i为根的子树中保留j个枝最多剩多少苹果 #include<bits/stdc++.h> using namespace std; int a[110][110],dp[110][110]; int n
阅读全文
摘要:https://www.luogu.com.cn/problem/P1052 设f[i]表示到达i位置最少踩到石子个数 f[i]从f[i-t]到f[i-s]转移 但是l太大要压缩路径 1.根据小凯的疑惑中的结论 方程px+(p+1)y=z,当z>=p(p+1)-p-(p+1)时一定有解 在本题中步数
阅读全文
摘要:http://ybt.ssoier.cn:8088/problem_show.php?pid=1172 #include<bits/stdc++.h> using namespace std; int cc[100000]; int main() { int n; cin>>n; int lenc=
阅读全文
摘要:https://www.luogu.com.cn/problem/P1020 #include<bits/stdc++.h> using namespace std; int a[1000000],l[1000000]; int main() { int n=1,cnt=0,len1=1; whil
阅读全文
摘要:https://www.luogu.com.cn/problem/P1480 #include<bits/stdc++.h> using namespace std; char a[50000]; int aa[50000],cc[50000]; int main() { int bb; cin>>
阅读全文
摘要:https://www.luogu.com.cn/problem/P2841 #include<bits/stdc++.h> using namespace std; char a[30000],b[30000]; int aa[30000],bb[30000],cc[30000]; int mai
阅读全文
摘要:https://www.luogu.com.cn/problem/P2142 #include<bits/stdc++.h> using namespace std; char a[100860],b[100860]; int aa[100860],bb[100860],cc[100860]; in
阅读全文
摘要:https://www.luogu.com.cn/problem/P1601 #include<bits/stdc++.h> using namespace std; string a,b; int aa[1000],bb[1000],cc[1000],lenc; int main() { mems
阅读全文
摘要:http://ybt.ssoier.cn:8088/problem_show.php?pid=1224 类似最大子段和 枚举矩阵的左端点i和右端点j 将每一行的i到j之间的区间和(前缀和求出)视为一个元素,求由它们构成的数列中的最大子段和 时间复杂度o(n^3) #include<bits/stdc
阅读全文
摘要:https://www.luogu.com.cn/problem/P1115 b[i]为以a[i]为结尾的子段中的最大子段和 1. 非空子段: b[i]=max(a[i],b[i-1]+a[i]); 2. 可以为空的子段: b[i]=max(0,a[i],b[i-1]+a[i]); 因为b[i-1]
阅读全文
摘要:http://ybt.ssoier.cn:8088/problem_show.php?pid=1320 #include<bits/stdc++.h> using namespace std; int a[661]; int main() { int n,sum=0,eve,ans=0; cin>>
阅读全文
摘要:https://www.luogu.com.cn/problem/P2363 #include<bits/stdc++.h> using namespace std; int a[2100][2100],dp[2280][2280],f[10111000]; void read(int &x) {
阅读全文
摘要:https://www.luogu.com.cn/problem/P1944 1. 遇到左括号加1右括号减1无法判断【(】)的情况 将括号压入栈中来判断是否合法,左括号直接压进去,右括号与栈顶元素比较,匹配则弹出来,不匹配返回不合法 所有括号都扫完之后记得检查栈是否为空 2. 枚举左端点i,从左往右
阅读全文
摘要:https://www.luogu.com.cn/problem/P1021 爆搜搜邮票面值,完全背包验证 设dp[j]为面值为j时所用最少邮票数,小于总邮票数则合法 #include<bits/stdc++.h> using namespace std; int n,k,dp[10010],ans
阅读全文
摘要:https://www.luogu.com.cn/problem/CF460C 二分答案+差分 #include<bits/stdc++.h> using namespace std; long long n,m,w,a[1000000],l=0,r=1e10,sum[1000000],aa[100
阅读全文
摘要:https://www.luogu.com.cn/problem/CF845C 差分+离散化 #include<bits/stdc++.h> using namespace std; int a[700100],s[700100],se[700100],e[700100];//2*n的范围 int
阅读全文
摘要:http://ybt.ssoier.cn:8088/problem_show.php?pid=1671 考虑贪心,牌组数取决于数量最少的牌,所以用joker来替换数量最少的牌 用小根堆维护,每次取出最少的牌,将其数量加一,joker数量减一,答案加一 如果同时有两种牌不够用则凑不出来,用堆顶元素与答
阅读全文
摘要:https://www.luogu.com.cn/problem/P1731 题目描述 已知蛋糕体积和层数,求表面积的最小值。 输入 第一行为一个整数N(N≤2×10^4),表示待制作的蛋糕的体积为 Nπ。 第二行为M(M≤15),表示蛋糕的层数为M。 输出格式 输出一个整数 S为蛋糕的表面积(除下
阅读全文

浙公网安备 33010602011771号