首页 > 其他分享 >Welcome to the Internet. What would you prefer?

Welcome to the Internet. What would you prefer?

时间:2024-04-06 16:22:41浏览次数:10  
标签:What would int siz Welcome prefer Internet

前言:今天 T1 数据也太水了。

void dfs(int u, int fa, int l) {
	siz[u] = 1;
	tsum[u] = a[u];
	f[u][0] = l * abs(a[u] - x);
	f[u][1] = l * abs(a[u] - y);
	for (const auto &i : e[u]) {
		int v = i.first, w = i.second;
		if (v == fa) continue;
		dfs(v, u, w);
		for (int i = min(siz[u] + siz[v], m); ~i; i--) {
			res[i] = 1e18;
			for (int j = 0; j <= min(siz[v], i); j++)
				res[i] = min(res[i], f[u][i - j] + f[v][j] - l * abs(tsum[u] - y * (i - j) - x * (siz[u] - (i - j))) + l * abs(tsum[u] + tsum[v] - y * i - x * (siz[u] + siz[v] - i)));
		}
		for (int i = min(siz[u] + siz[v], m); ~i; i--) f[u][i] = res[i];
		siz[u] += siz[v];
		tsum[u] += tsum[v];
	}
}

首先是一个很正常的树上背包,应该都看得出来。

这是过不了我随便随机的一组极限数据的,但是能在 OJ 上 A。

原因是它退化到了 \(O(nm ^ 2)\)。

为什么呢?感觉没有什么问题啊?

其实还是没有排除完冗余情况。

因为要保证 \(i - j \leq siz_u\),所以 \(j\) 的下界应该是 \(\max(0, i - siz_u)\)。这样就可以过了。

还是要尤其注意,,,复杂度证明:Link


本来以为可以探究点什么,没想到单纯是约束少了,,,

以及数据在这里:Link

标签:What,would,int,siz,Welcome,prefer,Internet
From: https://www.cnblogs.com/liuzimingc/p/18117531/tree-bag

相关文章

  • What is the difference between Mysql InnoDB B+ tree index and hash index? Why do
    原文:WhatisthedifferencebetweenMysqlInnoDBB+treeindexandhashindex?WhydoesMongoDBuseB-tree?|byMinaAyoub|MediumThemostimportantdifferencebetweenB-treeandB+treeisthatB+treeonlyhasleafnodestostoredata,andothernodes......
  • WHAT - 值得掌握的 computed 计算属性机制
    目录一、介绍二、计算属性vs方法:缓存优势三、计算属性vswatch1.主要区别:目的和用法2.watch性能问题四、计算属性底层实现五、计算属性只读和可写六、最佳实践1.不应该有副作用2.避免直接修改计算属性值一、介绍参考阅读:vue3官方文档......
  • 红队笔记10:pWnOS2.0打靶流程-whatweb指纹识别-searchsploit搜索漏洞利用getshell(vulnh
    目录开头:1.主机发现和端口扫描2.80端口- whatweb指纹识别-searchsploit搜索漏洞并利用whatweb指纹识别:searchsploit搜索历史漏洞:什么是perl?SimplePHPblog登录成功-图片上传getshell3.提权-敏感文件泄露密码泄露尝试登录 4.总结:开头:学习的视频是哔哩哔哩红......
  • android小球(二)——用户数据缓存详解SharedPreferences
    SharedPreferences概述SharedPreferences是Android平台上一个轻量级的存储辅助类,用来保存应用的一些常用配置,它提供了String,set,int,long,float,boolean六种数据类型。使用SharedPreferences进行存储的数据是存放在一个XML文件中的,同时它的存储方式是是以key-value的形式,key对应......
  • cppreference 速通指北
    本文将简要介绍cppreference的cpp部分中,较为古典且常用的部分同时,本文也尽量包含部分在特定场景中较为实用的内容注意:许多较为现代的,或者更多应用于项目的内容并未提及,请自行查找#容器库在阅读以下容器的相关页面时,可以留心迭代器概念:可以将其理解为包装过的指针本部......
  • What I have learnt and my suggestion
    收获:Fromthefirsttwoworkshops,Igainedthatthereare5modesofmutimodalitywhichmakeitmorevividtocharacterizepeopleandletaudienceinvolvedinit.These5modesincludelanguage,music,imageandsoon.What'more,Iamexposedtopedagogicm......
  • prefer 组合 to 继承
    核心不要多继承,要通过组合的模式进行组合,解耦,非强绑定需求我已有一个CodingService的接口,同时有一个CodingServiceImpl的实现类,接口中定义了createReository,pullCode,pushCode三个方法,CodingServiceImpl实现类里面进行了实现,现在想通过prefer组合to继承的思想,将接口中的3......
  • 【论文阅读】SpectFormer: Frequency and Attention is what you need in a Vision Tr
    SpectFormer:FrequencyandAttentioniswhatyouneedinaVisionTransformer引用:PatroBN,NamboodiriVP,AgneeswaranVS.SpectFormer:FrequencyandAttentioniswhatyouneedinaVisionTransformer[J].arXivpreprintarXiv:2304.06446,2023.论文......
  • What is Rust's turbofish
    Haveyoueverheardaboutthe“turbofish”?ItisthatpieceofRustsyntaxthatlookslike ::<SomeType>.InthispostIwilldescribewhatitdoesandhowtouseit.Firstof,ifyouweretowritesomethinglikethis:fnmain(){letnumbers:Ve......
  • PbRL Preference Transformer
    论文题目:PreferenceTransformer:ModelingHumanPreferencesusingTransformersforRL,ICLR2023,5668,poster。pdf:https://arxiv.org/pdf/2303.00957.pdfhtml:https://ar5iv.labs.arxiv.org/html/2303.00957openreview:https://openreview.net/forum?id=Peot1SFDX0项......