随笔分类 -  树结构

摘要:题目链接 https://vjudge.net/contest/240074#overview 只写一下自己做的几个题吧 阅读全文
posted @ 2018-07-26 19:36 一入OI深似海 阅读(177) 评论(0) 推荐(0)
摘要:/* 想了半天没想出状态 自己还是太弱了 QAQ 题目问的是最多供给多少户 一般想法是把这个值定义为状态量 没想出来QAQ....看了看题解的状态 很机智.... f[i][j]表示i的子树 选了j个叶子的最大收益 这样 不亏本就是收益>=0 转移的话 先搜一下这个子树有几个叶子 然后枚举儿子 枚举当前儿子分几个叶子 这里的枚举顺序有套路 从大到小枚举i分几个 从小到大枚举j分几个 这样可... 阅读全文
posted @ 2016-09-01 21:37 一入OI深似海 阅读(576) 评论(0) 推荐(0)
摘要:/* 开始想耍小聪明 直接map搞 代码短 好理解 空间够 恩 很好 就是 map慢死了 T了 */ #include #include #include #include using namespace std; int n,m,ans; string s,si; mapt; int main() { cin>>n; while(n--) { ... 阅读全文
posted @ 2016-07-11 15:02 一入OI深似海 阅读(152) 评论(0) 推荐(0)
摘要:/* 这题倒是没啥难度 字典树可搞 但是吧 空间是个问题 开始写成这样 struct node { int next[27],sum[27]; bool over; }t[maxn]; 死活过不了 开小了er 开大了MLE 问了问wmy 很机智的说用map 管用的 然后卡空间过了 看他们用指针动态分配内存 然而我并不太会..... */ #include #inclu... 阅读全文
posted @ 2016-07-11 10:44 一入OI深似海 阅读(185) 评论(0) 推荐(0)
摘要:/* WTF 写了好久了 开始的时候题目读错了 建图建错了 搜索写的也不好 感觉会T 总之 第一次写的很low 贴一下吧 */ #include #include #include #define N 40 #define M 40 using namespace std; int n,g[N*N][N*N],a[5][M*M]; int num[5],ans,maxx,f[N*N]... 阅读全文
posted @ 2016-06-12 20:20 一入OI深似海 阅读(197) 评论(0) 推荐(0)
摘要:/* 维护区间最小值 数据不超int 相反如果long long的话会有一组数据超时 无视掉 ll int */ #include #include #include #define maxn 1000010 #define ll int #define inf 0x7fffffff using namespace std; ll n,m,num,a[maxn],falg; struct n... 阅读全文
posted @ 2016-06-04 15:01 一入OI深似海 阅读(321) 评论(0) 推荐(0)
摘要:/* b本树较弱 支持插入+查询(删除太麻烦0.0) 复杂度 对于随机数据O(n*logn) 特殊的 如果一条链下来 O(n*n) (升级版:平衡树. ) */ #include #include #include #define maxn 100010 using namespace std; struct node { int lch; int rch; int ... 阅读全文
posted @ 2016-05-05 22:09 一入OI深似海 阅读(225) 评论(0) 推荐(0)
摘要:/* 树状数组前缀和 虽然只资词单点修改 区间查询 但是好写 pos&(-pos) 很神奇的东西 求前缀和 负数的二进制表示用补码(对应整数的反码+1) */ #include #include #include using namespace std; int tree[100010],n,m; void Add(int pos,int data) { while(pos>n; ... 阅读全文
posted @ 2016-05-05 22:03 一入OI深似海 阅读(140) 评论(0) 推荐(0)
摘要:/* 本字典树较弱 只支持插入单词 查询单词. 特殊的 bool变量w 标记此字母是不是某个单词的结束 (然而这个题并没卵用) */ #include #include #include #define maxn 300010 #define maxm 1010 using namespace std; char s[maxm]; struct node { int next[27];... 阅读全文
posted @ 2016-05-05 21:59 一入OI深似海 阅读(191) 评论(0) 推荐(1)