USACO
洛谷P1217 [USACO1.5]回文质数 Prime Palindromes
#include<bits/stdc++.h> using namespace std; int a,b; bool zs(int x) { if(x%2>0) { for(int i=3;i<x;i+=2) if(x%i==0) return false; return true; }else r ......
P6146 [USACO20FEB]Help Yourself G 题解
题目链接 先按左端点从小到大排序。 设 $f(i)$ 表示前 $i$ 条线段的所有子集的复杂度之和。 考虑从 $f(i-1)$ 转移到 $f(i)$,即考虑新加进来第 $i$ 条线段的过程。第 $i$ 条线段加进来所新产生的贡献分两种: 设除了第 $i$ 条线段选中的线段集合为 $S$,则若 $S$ ......
洛谷 P2986 [USACO10MAR] Great Cow Gathering G(树形DP/换根DP)
https://www.luogu.com.cn/problem/P2986 输入 #1 5 1 1 0 0 2 1 3 1 2 3 2 3 4 3 4 5 3 输出 #1 15 推荐这位佬的思路以及题解 https://zhuanlan.zhihu.com/p/571948153 #include ......
P3033 [USACO11NOV]Cow Steeplechase G
给出 N 条平行于坐标轴的线段,要你选出尽量多的线段使得这些线段两两没有交点(顶点也算)。 横的与横的,竖的与竖的线段之间保证没有交点,输出最多能选出多少条线段。 #include <iostream> #include <algorithm> #include <cstring> #include ......
[USACO08FEB]Hotel G 线段树区间合并|维护最长的连续1
这个还是看代码,比讲的清楚 #include<bits/stdc++.h> #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define ls (rt<<1) #define rs (rt<<1|1) u ......